平安校园
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.
 
 
 
 
 
 

44 lines
1.2 KiB

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