public static IWebHostBuilder UseStartupModules(this IWebHostBuilder builder, Action <StartupModulesOptions> configure) { if (builder == null) { throw new ArgumentNullException(nameof(builder)); } var options = new StartupModulesOptions(); options.DiscoverStartupModules(); if (configure == null) { throw new ArgumentNullException(nameof(configure)); } configure(options); if (options.StartupModules.Count == 0) { return(builder); } var runner = new StartupModuleRunner(options); builder.ConfigureServices((hostContext, services) => { //注册 IStartupFilter实现 services.AddSingleton <IStartupFilter>(sp => ActivatorUtilities.CreateInstance <ModulesStartupFilter>(sp, runner)); runner.ConfigureServices(services, hostContext.Configuration, hostContext.HostingEnvironment); }); return(builder); }
public StartupModuleRunner(StartupModulesOptions options) { _options = options; }
public ConfigureServicesContext(IConfiguration configuration, IWebHostEnvironment hostEnvironment, StartupModulesOptions options) { Configuration = configuration; HostEnvironment = hostEnvironment; Options = options; }