Exemple #1
0
        public static IWebHostBuilder UseStartupModules(this IWebHostBuilder builder, Action <StartupModulesOptions> configure)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (configure == null)
            {
                throw new ArgumentNullException(nameof(configure));
            }

            var options = new StartupModulesOptions();

            configure(options);

            if (options.StartupModules.Count == 0 && options.ApplicationInitializers.Count == 0)
            {
                return(builder);
            }

            var runner = new StartupModuleRunner(options);

            builder.ConfigureServices((hostContext, services) =>
            {
                services.AddSingleton <IStartupFilter>(sp => ActivatorUtilities.CreateInstance <ModulesStartupFilter>(sp, runner));

                runner.ConfigureServices(services, hostContext.Configuration, hostContext.HostingEnvironment);
            });

            return(builder);
        }
Exemple #2
0
 public ConfigureServicesContext(IConfiguration configuration, IWebHostEnvironment hostEnvironment, StartupModulesOptions options)
 {
     Configuration      = configuration;
     HostingEnvironment = hostEnvironment;
     Options            = options;
 }
 public StartupModuleRunner(StartupModulesOptions options)
 {
     _options = options;
 }