/// <summary> /// 添加模块 /// </summary> /// <param name="services"></param> /// <param name="env"></param> /// <returns></returns> public static IModuleCollection AddModules(this IServiceCollection services, IHostingEnvironment env) { var modules = new ModuleCollection(); services.AddSingleton <IModuleCollection>(modules); var cfgHelper = new ConfigurationHelper(); var cfg = cfgHelper.Load("module", env.EnvironmentName, true); foreach (var module in modules) { if (module == null) { continue; } services.AddApplicationServices(module); if (module.Initializer != null) { module.Initializer.ConfigureServices(services); module.Initializer.ConfigOptions(services, cfg.GetSection(module.Id)); services.AddSingleton(module); } } return(modules); }
/// <summary> /// 添加模块 /// </summary> /// <param name="services"></param> /// <returns></returns> public static IModuleCollection AddModules(this IServiceCollection services) { var modules = new ModuleCollection(); services.AddSingleton <IModuleCollection>(modules); foreach (var module in modules) { services.AddApplicationServices(module); module.Initializer?.ConfigureServices(services); } return(modules); }