namespace SafeCampus.Web.Core; /// /// Web设置组件 /// 模拟 ConfigureService /// public sealed class WebSettingsComponent : IServiceComponent { public void Load(IServiceCollection services, ComponentContext componentContext) { // 配置ip2region services.AddSingleton(new Searcher(CachePolicy.Content, Path.Combine(App.HostEnvironment.ContentRootPath, "ip2region.xdb"))); //web设置配置转实体 services.AddConfigurableOptions(); //禁止在主机启动时通过 App.GetOptions 获取选项,如需获取配置选项理应通过 App.GetConfig("配置节点", true)。 var appSettings = App.GetConfig("WebSettings", true); //如果是演示环境,加上操作筛选器,禁止操作数据库 if (appSettings.EnvPoc) services.AddMvcFilter(); } } /// /// Web设置组件 /// 模拟 Configure /// public sealed class WebSettingsApplicationComponent : IApplicationComponent { public void Load(IApplicationBuilder app, IWebHostEnvironment env, ComponentContext componentContext) { } }