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

3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
1234567891011121314151617181920212223242526272829303132333435
  1. 
  2. //
  3. using SafeCampus.Core.Options;
  4. namespace SafeCampus.Application;
  5. /// <summary>
  6. /// AppStartup启动类
  7. /// </summary>
  8. public class Startup : AppStartup
  9. {
  10. /// <summary>
  11. /// ConfigureServices中不能解析服务,比如App.GetService(),尤其是不能在ConfigureServices中获取诸如缓存等数据进行初始化,应该在Configure中进行
  12. /// 服务都还没初始化完成,会导致内存中存在多份 IOC 容器!!
  13. /// 正确应该在 Configure 中,这个时候服务(IServiceCollection 已经完成 BuildServiceProvider() 操作了
  14. /// </summary>
  15. /// <param name="services"></param>
  16. public void ConfigureServices(IServiceCollection services)
  17. {
  18. //业务配置转实体
  19. services.AddConfigurableOptions<ApplicationSettingsOptions>();
  20. services.AddConfigurableOptions<AppInfoOptions>();
  21. services.AddConfigurableOptions<TXSmsOptions>();
  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<ApplicationSettingsOptions>();
  28. CodeFirstUtils.CodeFirst(settings, fullName);//CodeFirst
  29. }
  30. }