平安校园
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 
 

42 righe
1.2 KiB

  1. //
  2. namespace SafeCampus.System;
  3. /// <summary>
  4. /// AppStartup启动类
  5. /// </summary>
  6. public class Startup : AppStartup
  7. {
  8. /// <summary>
  9. /// ConfigureServices中不能解析服务,比如App.GetService(),尤其是不能在ConfigureServices中获取诸如缓存等数据进行初始化,应该在Configure中进行
  10. /// 服务都还没初始化完成,会导致内存中存在多份 IOC 容器!!
  11. /// 正确应该在 Configure 中,这个时候服务(IServiceCollection 已经完成 BuildServiceProvider() 操作了
  12. /// </summary>
  13. /// <param name="services"></param>
  14. public void ConfigureServices(IServiceCollection services)
  15. {
  16. //系统配置转实体
  17. services.AddConfigurableOptions<SystemSettingsOptions>();
  18. //事件总线
  19. services.AddEventBus();
  20. //配置验证码
  21. services.AddCaptcha(App.Configuration);
  22. }
  23. public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
  24. {
  25. var fullName = Assembly.GetExecutingAssembly().FullName;//获取程序集全名
  26. //通过 App.GetOptions<TOptions> 获取选项
  27. var settings = App.GetOptions<SystemSettingsOptions>();
  28. CodeFirstUtils.CodeFirst(settings, fullName);//CodeFirst
  29. }
  30. }