Esempio n. 1
0
        public static IWebHostBuilder ConfigureBundleSink(this IWebHostBuilder builder, Action <ISinkConfiguration> configurationBuilder)
        {
            var configuration = new SinkConfiguration();

            configurationBuilder(configuration);

            return(builder
                   .ConfigureAppConfiguration(configurationBuilder =>
            {
                configurationBuilder.AddJsonFile(configuration.WebpackManifestName, true, true);
            })
                   .ConfigureServices((builderContext, services) =>
            {
                var settings = new BundleSinkSettings()
                {
                    PublicOutputPath = configuration.WebpackPublicOutputPath,
                    AppendVersion = configuration.AppendVersion,
                    PrintAllAttributes = configuration.PrintAdditionalAttributesCondition(builderContext.HostingEnvironment),
                    PrintComments = configuration.PrintCommentsCondition(builderContext.HostingEnvironment),
                    CheckIntegrity = configuration.IntegrityCheckCondition(builderContext.HostingEnvironment),
                    RewriteOutput = configuration.RewriteOutput,
                    UsePlainIOptions = configuration.UsePlainIOptionsCondition(builderContext.HostingEnvironment),
                };

                services.AddSingleton(settings);
                services.AddHttpContextAccessor();
                services.Configure <WebpackEntriesManifest>(builderContext.Configuration.GetSection(WebpackEntriesManifest.SECTION_NAME));
                services.AddScoped <EntriesViewData>();
                services.AddTransient <SinkService>();
                services.AddSingleton <IConfigureOptions <MvcOptions>, ConfigureMvcOptions>();

                if (settings.UsePlainIOptions)
                {
                    services.AddScoped <EntriesManifest>(sp => new EntriesManifest(sp.GetRequiredService <IOptions <WebpackEntriesManifest> >().Value));
                }
                else
                {
                    services.AddScoped <EntriesManifest>(sp => new EntriesManifest(sp.GetRequiredService <IOptionsSnapshot <WebpackEntriesManifest> >().Value));
                }
            }));
        }