/// <summary> /// Initializes a new instance of the <see cref="ConfigureServicesContext"/> class. /// </summary> public ConfigureMiddlewareContext(IConfiguration configuration, IWebHostEnvironment hostingEnvironment, IServiceProvider serviceProvider, StartupModulesOptions options) { Configuration = configuration; HostingEnvironment = hostingEnvironment; ServiceProvider = serviceProvider; Options = options; }
/// <summary> /// Configures startup modules with the specified configuration for <see cref="StartupModulesOptions"/>. /// </summary> /// <param name="builder">The <see cref="IWebHostBuilder"/> instance.</param> /// <param name="configure">A callback to configure <see cref="StartupModulesOptions"/>.</param> /// <returns>The <see cref="IWebHostBuilder"/> instance.</returns> 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) { // Nothing to do here return(builder); } var runner = new StartupModuleRunner(options); builder.ConfigureServices((hostContext, services) => { services.AddSingleton <IStartupFilter>(sp => ActivatorUtilities.CreateInstance <ModulesStartupFilter>(sp, runner)); var configureServicesContext = new ConfigureServicesContext(hostContext.Configuration, hostContext.HostingEnvironment, options); runner.ConfigureServices(services, hostContext.Configuration, hostContext.HostingEnvironment); }); return(builder); }
/// <summary> /// Initializes a new instance of the <see cref="StartupModuleRunner"/> class. /// </summary> /// <param name="options">The <see cref="StartupModulesOptions"/> to discover <see cref="IStartupModule"/>'s.</param> public StartupModuleRunner(StartupModulesOptions options) { _options = options; }
/// <summary> /// Initializes a new instance of the <see cref="ConfigureServicesContext"/> class. /// </summary> public ConfigureServicesContext(IConfiguration configuration, IWebHostEnvironment hostingEnvironment, StartupModulesOptions options) { Configuration = configuration; HostingEnvironment = hostingEnvironment; Options = options; }