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

Startup.cs 1.2 KiB

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