public static IServiceProvider ConfigureApplicationServices(this IServiceCollection services, IConfiguration configuration) { //add Default configuration parameters services.ConfigureStartupConfig <DefaultConfig>(configuration.GetSection("Default")); //add hosting configuration parameters services.ConfigureStartupConfig <HostingConfig>(configuration.GetSection("Hosting")); //add accessor to HttpContext services.AddHttpContextAccessor(); // initialize singleton app var engine = EngineContext.Create(); engine.Initialize(services); var serviceProvider = engine.ConfigureServices(services, configuration); if (!DataSettingsManager.DatabaseIsInstalled) { return(serviceProvider); } //log application start engine.Resolve <ILogger>().Information("Application started"); //install plugins engine.Resolve <IPluginService>().InstallPlugins(); return(serviceProvider); }
/// <summary> /// Add services to the application and configure service provider /// </summary> /// <param name="services">Collection of service descriptors</param> /// <param name="configuration">Configuration root of the application</param> /// <returns>Configured service provider</returns> public static IServiceProvider ConfigureApplicationServices(this IServiceCollection services, IConfiguration configuration) { //add GrandConfig configuration parameters services.ConfigureStartupConfig <GrandConfig>(configuration.GetSection("Grand")); //add hosting configuration parameters services.ConfigureStartupConfig <HostingConfig>(configuration.GetSection("Hosting")); //add api configuration parameters services.ConfigureStartupConfig <ApiConfig>(configuration.GetSection("Api")); //add accessor to HttpContext services.AddHttpContextAccessor(); //create, initialize and configure the engine var engine = EngineContext.Create(); engine.Initialize(services); var serviceProvider = engine.ConfigureServices(services, configuration); if (DataSettingsHelper.DatabaseIsInstalled()) { //log application start var logger = serviceProvider.GetRequiredService <ILogger>(); logger.Information("Application started", null, null); } return(serviceProvider); }
/// <summary> /// Add services to the application and configure service provider /// </summary> /// <param name="services">Collection of service descriptors</param> /// <param name="configuration">Configuration of the application</param> /// <param name="hostingEnvironment">Hosting environment</param> /// <returns>Configured service provider</returns> public static IServiceProvider ConfigureApplicationServices(this IServiceCollection services, IConfiguration configuration, IHostingEnvironment hostingEnvironment) { //add HttpContext accessor services.AddHttpContextAccessor(); //add CORS services.AddCors(); //add MVC services.AddMvc(); //add dbcontext var connectionString = configuration["ConnectionStrings:Registry"].ToString(); services.AddDbContext <RegistryDbContext>(t => t.UseSqlServer(connectionString, x => x.UseNetTopologySuite())); //create engine var engine = EngineContext.Create(); var serviceProvider = engine.ConfigureServices(services); var sqlProvider = new SqlServerDataProvider(); sqlProvider.InitializeDatabase(); return(serviceProvider); }
/// <summary> /// Add services to the application and configure service provider /// </summary> /// <param name="services">Collection of service descriptors</param> /// <param name="configuration">Configuration root of the application</param> /// <returns>Configured service provider</returns> public static IServiceProvider ConfigureApplicationServices(this IServiceCollection services, IConfigurationRoot configuration) { //add NopConfig configuration parameters services.ConfigureStartupConfig <CH3Config>(configuration.GetSection("CH3")); //add hosting configuration parameters services.ConfigureStartupConfig <HostingConfig>(configuration.GetSection("Hosting")); //add accessor to HttpContext services.AddHttpContextAccessor(); //create, initialize and configure the engine var engine = EngineContext.Create(); engine.Initialize(services); var serviceProvider = engine.ConfigureServices(services, configuration); var dataProviderInstance = EngineContext.Current.Resolve <BaseDataProviderManager>().LoadDataProvider(); dataProviderInstance.InitDatabase(); //now resolve installation service if (!DataSettingsHelper.DatabaseIsInstalled()) { var installationService = EngineContext.Current.Resolve <IInstallationService>(); installationService.InstallData(string.Empty, string.Empty, false); } return(serviceProvider); }
/// <summary> /// Add services to the application and configure service provider /// </summary> /// <param name="services">Collection of service descriptors</param> /// <param name="configuration">Configuration of the application</param> /// <param name="hostingEnvironment">Hosting environment</param> /// <returns>Configured service provider</returns> public static IServiceProvider ConfigureApplicationServices(this IServiceCollection services, IConfiguration configuration, IHostingEnvironment hostingEnvironment) { //most of API providers require TLS 1.2 nowadays ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; //add AldanConfig configuration parameters var aldanConfig = services.ConfigureStartupConfig <AldanConfig>(configuration.GetSection("Aldan")); //add accessor to HttpContext services.AddHttpContextAccessor(); //create default file provider CommonHelper.DefaultFileProvider = new AldanFileProvider(hostingEnvironment); //initialize plugins var mvcCoreBuilder = services.AddMvcCore(); //create engine and configure service provider var engine = EngineContext.Create(); var serviceProvider = engine.ConfigureServices(services, configuration, aldanConfig); //initialize and start schedule tasks TaskManager.Instance.Initialize(); TaskManager.Instance.Start(); //log application start engine.Resolve <ILogger>().Information("Application started"); return(serviceProvider); }
// This method gets called by the runtime. Use this method to add services to the container. public IServiceProvider ConfigureServices(IServiceCollection services) { //services.Configure<CookiePolicyOptions>(options => //{ // // This lambda determines whether user consent for non-essential cookies is needed for a given request. // options.CheckConsentNeeded = context => true; // options.MinimumSameSitePolicy = Microsoft.AspNetCore.Http.SameSiteMode.None; //}); var infrastructureOptions = new FrameworkInfrastructureOptions(); Configuration.Bind(infrastructureOptions); services.AddSingleton(infrastructureOptions); var pluginOptions = new FrameworkPluginOptions(); Configuration.Bind(pluginOptions); services.AddSingleton(pluginOptions); var engine = EngineContext.Create(new AutofacEngine()); engine.Initialize(services); var serviceProvider = engine.ConfigureServices(services, Configuration); return(serviceProvider); }
/// <summary> /// Add services to the application and configure service provider /// </summary> /// <param name="services">Collection of service descriptors</param> /// <param name="configuration">Configuration of the application</param> /// <param name="webHostEnvironment">Hosting environment</param> /// <returns>Configured engine and app settings</returns> public static (IEngine, AppSettings) ConfigureApplicationServices(this IServiceCollection services, IConfiguration configuration, IWebHostEnvironment webHostEnvironment) { //let the operating system decide what TLS protocol version to use //see https://docs.microsoft.com/dotnet/framework/network-programming/tls ServicePointManager.SecurityProtocol = SecurityProtocolType.SystemDefault; //create default file provider CommonHelper.DefaultFileProvider = new NopFileProvider(webHostEnvironment); //add accessor to HttpContext services.AddHttpContextAccessor(); //add configuration parameters var appSettings = new AppSettings(); configuration.Bind(appSettings); services.AddSingleton(appSettings); AppSettingsHelper.SaveAppSettings(appSettings); //initialize plugins var mvcCoreBuilder = services.AddMvcCore(); mvcCoreBuilder.PartManager.InitializePlugins(appSettings); //create engine and configure service provider var engine = EngineContext.Create(); engine.ConfigureServices(services, configuration); engine.RegisterDependencies(services, appSettings); return(engine, appSettings); }
/// <summary> /// Add services to the application and configure service provider /// </summary> /// <param name="services">Collection of service descriptors</param> /// <param name="configuration">Configuration of the application</param> /// <param name="webHostEnvironment">Hosting environment</param> /// <returns>Configured engine and app settings</returns> public static (IEngine, AppSettings) ConfigureApplicationServices(this IServiceCollection services, IConfiguration configuration, IWebHostEnvironment webHostEnvironment) { //most of API providers require TLS 1.2 nowadays ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; //create default file provider CommonHelper.DefaultFileProvider = new NopFileProvider(webHostEnvironment); //add accessor to HttpContext services.AddHttpContextAccessor(); //add configuration parameters var appSettings = new AppSettings(); configuration.Bind(appSettings); services.AddSingleton(appSettings); AppSettingsHelper.SaveAppSettings(appSettings); //initialize plugins var mvcCoreBuilder = services.AddMvcCore(); mvcCoreBuilder.PartManager.InitializePlugins(appSettings); //create engine and configure service provider var engine = EngineContext.Create(); engine.ConfigureServices(services, configuration); return(engine, appSettings); }
/// <summary> /// Add services to the application and configure service provider /// </summary> /// <param name="services">Collection of service descriptors</param> /// <param name="configuration">Configuration root of the application</param> /// <returns>Configured service provider</returns> public static IServiceProvider ConfigureApplicationServices(this IServiceCollection services, IConfiguration configuration) { //add YimiConfig configuration parameters services.ConfigureStartupConfig <YimiConfig>(configuration.GetSection("YimiConfig")); //add hosting configuration parameters services.ConfigureStartupConfig <HostingConfig>(configuration.GetSection("Hosting")); //add accessor to HttpContext services.AddHttpContextAccessor(); services.Configure <FormOptions>(x => { x.ValueLengthLimit = int.MaxValue; x.MultipartBodyLengthLimit = int.MaxValue; // In case of multipart }); //create, initialize and configure the engine var engine = EngineContext.Create(); engine.Initialize(services); var serviceProvider = engine.ConfigureServices(services, configuration); if (DataSettingsHelper.DatabaseIsInstalled()) { //log application start var logger = EngineContext.Current.Resolve <ILogger>(); logger?.Writelog("Application started"); } return(serviceProvider); }
/// <summary> /// 向应用程序添加服务并配置服务提供程序 /// </summary> /// <param name="services"></param> /// <param name="configuration"></param> /// <returns></returns> public static IServiceProvider ConfigureApplicationServices(this IServiceCollection services, IConfigurationRoot configuration) { //获取MapleConfig配置参数并将其以单例形式注入至IServiceCollection //MapleConfig = 系统配置信息 services.ConfigureStartupConfig <MapleConfig>(configuration.GetSection("Maple")); //获取HostingConfig配置参数并将其以单例形式注入至IServiceCollection //HostingConfig = 宿主机的配置信息 services.ConfigureStartupConfig <HostingConfig>(configuration.GetSection("Hosting")); //注册 HttpContextAccessor 单例 ,用于DI时注入IHttpContextAccessor,以获取类似 HttpContext.Current 的效果 services.AddHttpContextAccessor(); //创建 Maple 引擎 var engine = EngineContext.Create(); //初始化 Maple 引擎 [ 指定安全协议 \ 设置应用程序根目录 \ 初始化插件 ] engine.Initialize(services); //在DI容器中注册服务 [ 查询所有实现了IMapleStartup类的实例,并确保其所在插件均已被加载 \ 按顺序执行中间件的添加和配置 \ // 注册并配置AutoMapper \ 使用 Autofac 重新注册依赖关系 \ 运行 startup 启动时的任务 ] var serviceProvider = engine.ConfigureServices(services, configuration); if (MainDataSettingsHelper.DatabaseIsInstalled()) { ////如果数据库已完成配置和安装,那么开始执行计划任务 //TaskManager.Instance.Initialize(); //TaskManager.Instance.Start(); //标识用于程序已启动成功 EngineContext.Current.Resolve <ILogger <IServiceCollection> >().LogInformation("Maple Application 已启动..."); } return(serviceProvider); }
/// <summary> /// Add services to the application and configure service provider /// </summary> /// <param name="services">Collection of service descriptors</param> /// <param name="configuration">Configuration of the application</param> /// <param name="webHostEnvironment">Hosting environment</param> /// <returns>Configured service provider</returns> public static (IEngine, IChibaConfig) ConfigureApplicationServices(this IServiceCollection services, IConfiguration configuration, IWebHostEnvironment webHostEnvironment) { //most of API providers require TLS 1.2 nowadays ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; //add NopConfig configuration parameters services.Configure <IChibaConfig>(configuration.GetSection(IChibaConfig.IChiba)); //add hosting configuration parameters services.Configure <HostingConfig>(configuration.GetSection(HostingConfig.Hosting)); services.Configure <SSOConfig>(configuration.GetSection(SSOConfig.SSO)); var config = configuration.GetSection(IChibaConfig.IChiba).Get <IChibaConfig>(); //add accessor to HttpContext services.AddHttpContextAccessor(); //create default file provider CommonHelper.DefaultFileProvider = new IChibaFileProvider(webHostEnvironment); //initialize plugins var mvcCoreBuilder = services.AddMvcCore(); //create engine and configure service provider var engine = EngineContext.Create(); engine.ConfigureServices(services, configuration, config); return(engine, config); }
/// <summary> /// Add services to the application and configure service provider /// </summary> /// <param name="services">Collection of service descriptors</param> /// <param name="configuration">Configuration of the application</param> /// <param name="webHostEnvironment">Hosting environment</param> /// <returns>Configured service provider</returns> public static (IEngine, NopConfig) ConfigureApplicationServices(this IServiceCollection services, IConfiguration configuration, IWebHostEnvironment webHostEnvironment) { //most of API providers require TLS 1.2 nowadays ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; //add NopConfig configuration parameters var nopConfig = services.ConfigureStartupConfig <NopConfig>(configuration.GetSection("Nop")); //add hosting configuration parameters services.ConfigureStartupConfig <HostingConfig>(configuration.GetSection("Hosting")); //add accessor to HttpContext services.AddHttpContextAccessor(); //create default file provider CommonHelper.DefaultFileProvider = new NopFileProvider(webHostEnvironment); //initialize plugins var mvcCoreBuilder = services.AddMvcCore(); mvcCoreBuilder.PartManager.InitializePlugins(nopConfig); //create engine and configure service provider var engine = EngineContext.Create(); engine.ConfigureServices(services, configuration, nopConfig); return(engine, nopConfig); }
public static IServiceProvider ConfigureApiServices(this IServiceCollection services, IConfigurationRoot configuration, IHostingEnvironment environment) { //add application configuration parameters var config = services.ConfigureStartupConfig <ServiceConfiguration>(configuration.GetSection("Service")); //add hosting configuration parameters services.ConfigureStartupConfig <HostingConfiguration>(configuration.GetSection("Hosting")); //set paths the global configuration GlobalConfiguration.ApplicationRootPath = environment.ContentRootPath; GlobalConfiguration.ContentRootPath = environment.WebRootPath; GlobalConfiguration.ModulesRootPath = Path.Combine(environment.ContentRootPath, "Modules"); //create, initialize and configure the engine var engine = EngineContext.Create(); //most of API providers require TLS 1.2 nowadays ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; //add mvc engine services.AddWebApi(); //add accessor to HttpContext services.AddHttpContextAccessor(); //add swagger services.AddCustomizedSwagger(config); //register dependencies var serviceProvider = engine.RegisterDependencies(services, configuration, config); return(serviceProvider); }
/// <summary> /// Add services to the application and configure service provider /// </summary> /// <param name="services">Collection of service descriptors</param> /// <param name="configuration">Configuration root of the application</param> /// <returns>Configured service provider</returns> public static IServiceProvider ConfigureApplicationServices(this IServiceCollection services, IConfigurationRoot configuration) { //add NopConfig configuration parameters services.ConfigureStartupConfig <NopConfig>(configuration.GetSection("Nop")); //add hosting configuration parameters services.ConfigureStartupConfig <HostingConfig>(configuration.GetSection("Hosting")); //add accessor to HttpContext services.AddHttpContextAccessor(); //create, initialize and configure the engine var engine = EngineContext.Create(); engine.Initialize(services); var serviceProvider = engine.ConfigureServices(services, configuration); if (DataSettingsHelper.DatabaseIsInstalled()) { //implement schedule tasks //database is already installed, so start scheduled tasks TaskManager.Instance.Initialize(); TaskManager.Instance.Start(); //log application start EngineContext.Current.Resolve <ILogger>().Information("Application started", null, null); } return(serviceProvider); }
public static IServiceProvider ConfigureApplicationServices(this IServiceCollection services, IConfiguration configuration, IHostingEnvironment hostingEnvironment) { ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; var nopConfig = services.ConfigureStartupConfig <DbToRestConfig>(configuration.GetSection("DbToRest")); services.ConfigureStartupConfig <HostingConfig>(configuration.GetSection("Hosting")); services.AddHttpContextAccessor(); services.AddDbToRestAntiForgery(); services.AddDbToRestHttpSession(); services.AddDbToRestMvc(); services.AddCors(); services.AddEasyCaching(); CommonHelper.DefaultFileProvider = new DbToRestFileProvider(hostingEnvironment); var mvcCoreBuilder = services.AddMvcCore(); var engine = EngineContext.Create(); var serviceProvider = engine.ConfigureServices(services, configuration, nopConfig); if (!CommonHelper.DatabaseIsInstalled) { return(serviceProvider); } engine.Resolve <ILogService>().Info("Application started"); return(serviceProvider); }
public static void ConfigureApplicationServices(this IServiceCollection services, IConfiguration configuration) { services.AddHttpContextAccessor(); var engine = EngineContext.Create(); engine.ConfigureEngineServices(services, configuration); }
public void Should_Create_An_Instance_By_Itself() { var engine = EngineContext.Create(); Assert.Equal(engine, BaseSingleton.AllSingletons[typeof(IEngine)]); Assert.Equal(engine, EngineContext.Current); Assert.Equal(EngineContext.Current, Singleton <IEngine> .Instance); }
/// <summary> /// Add services to the application and configure service provider /// </summary> /// <param name="services">Collection of service descriptors</param> public IServiceProvider ConfigureServices(IServiceCollection services) { var engine = (AppWebApiEngine)EngineContext.Create <AppWebApiEngine>(); engine.Initialize(Configuration); return(engine.ConfigureServices(services)); }
/// <summary> /// Add services to the application and configure service provider /// </summary> /// <param name="services">Collection of service descriptors</param> /// <param name="configuration">Configuration root of the application</param> /// <returns></returns> public static IServiceProvider ConfigureApplicationServices(this IServiceCollection services, IConfigurationRoot configuration) { //create, initialize and configure the engine var engine = EngineContext.Create(); engine.Initialize(services); var serviceProvider = engine.ConfigureServices(services, configuration); return(serviceProvider); }
// This method gets called by the runtime. Use this method to add services to the container. public IServiceProvider ConfigureServices(IServiceCollection services) { services.AddHttpContextAccessor(); EngineContext.Create(); EngineContext.Replace(new CleanBlogApplication()); EngineContext.Current.Initialize(services); var serviceProvider = EngineContext.Current.ConfigureServices(services, Configuration); return(serviceProvider); }
public void Should_Register_Services_Dependencies() { var engine = EngineContext.Create(); engine.ConfigureServices(); var registeredServices = EngineContext.Current.ServiceCollection .Where(prop => prop.ServiceType.FullName.Contains(typeof(IDependencyRegistrar).Namespace.Split('.')[0])) .ToList(); Assert.Contains(registeredServices, prop => prop.ServiceType.FullName.Contains(nameof(IDependencyRegistrar))); }
public static IServiceProvider ConfigureApplicationServices(this IServiceCollection services, IConfiguration configuration, IHostingEnvironment hostingEnvironment) { //most of API providers require TLS 1.2 nowadays //目前,大多数API提供商都需要TLS 1.2 ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; //add NopConfig configuration parameters //添加nopconfig配置参数 var nopConfig = services.ConfigureStartupConfig <NopConfig> (configuration.GetSection("Nop")); //添加主机配置参数 services.ConfigureStartupConfig <HostingConfig>(configuration.GetSection("Hosting")); //add accessor to HttpContext //附加到httpconxt services.AddHttpContextAccessor(); //create default file provider //创建默认文件提供程序 CommonHelper.DefaultFileProvider = new NopFileProvider(hostingEnvironment); //initialize plugins //初始化插件 var mvcCoreBuilder = services.AddMvcCore(); mvcCoreBuilder.PartManager.InitializePlugins(nopConfig); //create engine and configure service provider //创建引擎并配置服务提供者 var engine = EngineContext.Create(); var serviceProvider = engine.ConfigureServices(services, configuration, nopConfig); //further actions are performed only when the database is installed //只有在安装数据库时才会执行进一步的操作 if (!DataSettingsManager.DatabaseIsInstalled) { return(serviceProvider); } //initialize and start schedule tasks //初始化并开始计划任务 TaskManager.Instance.Initialize(); TaskManager.Instance.Start(); //log application start //日志应用程序开始 engine.Resolve <ILogger>().Information("Application started"); //install plugins //安装插件 engine.Resolve <IPluginService>().InstallPlugins(); return(serviceProvider); }
public static IEngine ConfigureApplicationServices(this IServiceCollection services, IConfiguration configuration) { ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; services.AddHttpContextAccessor(); var engine = EngineContext.Create(); engine.ConfigureServices(services, configuration); return(engine); }
public static void ConfigureApplicationServices(this IServiceCollection services, IConfiguration configuration) { // add config var config = services.ConfigureStartupConfig <HarConfig>(configuration.GetSection("HarConfig")); services.AddHttpContextAccessor(); // create configure engine var engine = EngineContext.Create(); engine.ConfigureEngineServices(services, configuration, config); }
public static IServiceProvider ConfigureServices(this IServiceCollection services, IConfigurationRoot configuration) { services.ConfigureStartupConfig <AppConfig>(configuration.GetSection("App")); services.AddHttpContextAccessor(); var engine = EngineContext.Create(); engine.Initialize(services); engine.ConfigureServices(services, configuration); return(engine.IocManager.ServiceProvider); }
public static IServiceProvider ConfigureApplicationServices(this IServiceCollection services, IConfiguration configuration, IHostingEnvironment hostingEnvironment) { services.AddHttpContextAccessor(); var appconfig = services.ConfigureStartupConfig <AppConfig>(configuration.GetSection("App")); var engine = EngineContext.Create(); var serviceProvider = engine.ConfigureServices(services, configuration, appconfig); services.AddSerilog(); return(serviceProvider); }
public void Should_Replace_An_Instance() { var engine = EngineContext.Create(); engine.ConfigureServices(); var newEngine = new CoreEngine(); EngineContext.Replace(newEngine); Assert.Equal(EngineContext.Current, newEngine); Assert.Equal(EngineContext.Current.ServiceCollection.Count, newEngine.ServiceCollection.Count); Assert.NotEqual(EngineContext.Current.ServiceCollection.Count, engine.ServiceCollection.Count); }
public static IEngine ConfigureApplicationServices(this IServiceCollection services, IConfiguration configuration, IWebHostEnvironment webHostEnvironment) { CommonHelper.DefaultFileProvider = new AgileFileProvider(webHostEnvironment); var mvcCoreBuilder = services.AddMvcCore(); mvcCoreBuilder.PartManager.InitializePlugins(); var engine = EngineContext.Create(); engine.ConfigureServices(services, configuration); return(engine); }
public static IServiceProvider ConfigureServices(this IServiceCollection services, IConfiguration configuration, IHostingEnvironment hostingEnvironment) { //添加 accessor 到httpcontext services.AddHttpContextAccessor(); //配置 默认 file provider CommonHelper.DefaultFileProvider = new AAFileProvider(hostingEnvironment); //创建engine 配置服务提供者 var engine = EngineContext.Create(); var serviceProvider = engine.ConfigureServices(services, configuration); return(serviceProvider); }
// This method gets called by the runtime. Use this method to add services to the container. public IServiceProvider ConfigureServices(IServiceCollection services) { UseHttps = Configuration.GetValue <bool>("UseHttps"); if (UseHttps) { services.AddHttpsRedirection(opt => opt.HttpsPort = 443); } var engine = EngineContext.Create(new AbEngine(Configuration, Hosting)); engine.Initialize(services); var serviceProvider = engine.ConfigureServices(services); return(serviceProvider); }