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

34 lines
1.2 KiB

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