5
5
using Microsoft . AspNetCore . Builder ;
6
6
using Microsoft . AspNetCore . Hosting ;
7
7
using Microsoft . AspNetCore . StaticFiles ;
8
+ using Microsoft . Extensions . Configuration ;
8
9
using Microsoft . Extensions . DependencyInjection . Extensions ;
9
10
using Microsoft . Extensions . Options ;
10
11
@@ -14,34 +15,33 @@ public static class BlazorHostingServiceCollectionExtensions
14
15
{
15
16
public static IServiceCollection AddBlazorStaticFilesConfiguration ( this IServiceCollection services )
16
17
{
17
- services . Configure < StaticFileOptions > ( options =>
18
- {
19
- } ) ;
20
-
21
18
services . TryAddEnumerable ( ServiceDescriptor . Singleton < IConfigureOptions < StaticFileOptions > , ClientSideBlazorStaticFilesConfiguration > ( ) ) ;
22
-
23
19
return services ;
24
-
25
20
}
26
21
27
22
private class ClientSideBlazorStaticFilesConfiguration : IConfigureOptions < StaticFileOptions >
28
23
{
29
- public ClientSideBlazorStaticFilesConfiguration ( IWebHostEnvironment webHostEnvironment )
24
+ private readonly IConfiguration _configuration ;
25
+ private readonly IWebHostEnvironment _webHostEnvironment ;
26
+
27
+ public ClientSideBlazorStaticFilesConfiguration ( IConfiguration configuration , IWebHostEnvironment webHostEnvironment )
30
28
{
31
- WebHostEnvironment = webHostEnvironment ;
29
+ _configuration = configuration ;
30
+ _webHostEnvironment = webHostEnvironment ;
31
+ _webHostEnvironment = webHostEnvironment ;
32
32
}
33
33
34
- public IWebHostEnvironment WebHostEnvironment { get ; }
35
-
36
34
public void Configure ( StaticFileOptions options )
37
35
{
38
- options . FileProvider = WebHostEnvironment . WebRootFileProvider ;
36
+ options . FileProvider = _webHostEnvironment . WebRootFileProvider ;
39
37
var contentTypeProvider = new FileExtensionContentTypeProvider ( ) ;
40
38
AddMapping ( contentTypeProvider , ".dll" , MediaTypeNames . Application . Octet ) ;
41
- // For right now unconditionally enable debugging
42
- AddMapping ( contentTypeProvider , ".pdb" , MediaTypeNames . Application . Octet ) ;
39
+ if ( _configuration . GetValue < bool > ( "useWebAssemblyDebugging" ) )
40
+ {
41
+ AddMapping ( contentTypeProvider , ".pdb" , MediaTypeNames . Application . Octet ) ;
42
+ }
43
+
43
44
options . ContentTypeProvider = contentTypeProvider ;
44
- options . OnPrepareResponse = CacheHeaderSettings . SetCacheHeaders ;
45
45
}
46
46
47
47
private static void AddMapping ( FileExtensionContentTypeProvider provider , string name , string mimeType )
0 commit comments