平安校园
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

WebSettingsComponent.cs 1.2 KiB

4 months ago
12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. 
  2. //
  3. namespace SafeCampus.Web.Core;
  4. /// <summary>
  5. /// Web设置组件
  6. /// 模拟 ConfigureService
  7. /// </summary>
  8. public sealed class WebSettingsComponent : IServiceComponent
  9. {
  10. public void Load(IServiceCollection services, ComponentContext componentContext)
  11. {
  12. // 配置ip2region
  13. services.AddSingleton<ISearcher>(new Searcher(CachePolicy.Content, Path.Combine(App.HostEnvironment.ContentRootPath, "ip2region.xdb")));
  14. //web设置配置转实体
  15. services.AddConfigurableOptions<WebSettingsOptions>();
  16. //禁止在主机启动时通过 App.GetOptions<TOptions> 获取选项,如需获取配置选项理应通过 App.GetConfig<TOptions>("配置节点", true)。
  17. var appSettings = App.GetConfig<WebSettingsOptions>("WebSettings", true);
  18. //如果是演示环境,加上操作筛选器,禁止操作数据库
  19. if (appSettings.EnvPoc)
  20. services.AddMvcFilter<MyActionFilter>();
  21. }
  22. }
  23. /// <summary>
  24. /// Web设置组件
  25. /// 模拟 Configure
  26. /// </summary>
  27. public sealed class WebSettingsApplicationComponent : IApplicationComponent
  28. {
  29. public void Load(IApplicationBuilder app, IWebHostEnvironment env, ComponentContext componentContext)
  30. {
  31. }
  32. }