Program.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. using FreeScheduler;
  2. using Microsoft.Extensions.DependencyInjection;
  3. using Microsoft.Extensions.Hosting;
  4. using Savorboard.CAP.InMemoryMessageQueue;
  5. using System.Reflection;
  6. using ZhonTai;
  7. using ZhonTai.Admin.Core;
  8. using ZhonTai.Admin.Core.Configs;
  9. using ZhonTai.Admin.Core.Consts;
  10. using ZhonTai.Admin.Core.Startup;
  11. using ZhonTai.Admin.Tools.TaskScheduler;
  12. using ZhonTai.ApiUI;
  13. using ZhonTai.Common.Helpers;
  14. new HostApp(new HostAppOptions
  15. {
  16. //配置后置服务
  17. ConfigurePostServices = context =>
  18. {
  19. //context.Services.AddTiDb(context);
  20. //添加cap事件总线
  21. var appConfig = ConfigHelper.Get<AppConfig>("appconfig", context.Environment.EnvironmentName);
  22. Assembly[] assemblies = AssemblyHelper.GetAssemblyList(appConfig.AssemblyNames);
  23. //var dbConfig = ConfigHelper.Get<DbConfig>("dbconfig", context.Environment.EnvironmentName);
  24. //var rabbitMQ = context.Configuration.GetSection("CAP:RabbitMq").Get<RabbitMqConfig>();
  25. context.Services.AddCap(config =>
  26. {
  27. config.UseInMemoryStorage();
  28. config.UseInMemoryMessageQueue();
  29. //<PackageReference Include="DotNetCore.CAP.MySql" Version="7.1.0" />
  30. //<PackageReference Include="DotNetCore.CAP.RabbitMQ" Version="7.1.0" />
  31. //config.UseMySql(dbConfig.ConnectionString);
  32. //config.UseRabbitMQ(mqConfig => {
  33. // mqConfig.HostName = rabbitMQ.HostName;
  34. // mqConfig.Port = rabbitMQ.Port;
  35. // mqConfig.UserName = rabbitMQ.UserName;
  36. // mqConfig.Password = rabbitMQ.Password;
  37. // mqConfig.ExchangeName = rabbitMQ.ExchangeName;
  38. //});
  39. config.UseDashboard();
  40. }).AddSubscriberAssembly(assemblies);
  41. //添加任务调度
  42. context.Services.AddTaskScheduler(DbKeys.AppDb, options =>
  43. {
  44. options.ConfigureFreeSql = freeSql =>
  45. {
  46. freeSql.CodeFirst
  47. //配置任务表
  48. .ConfigEntity<TaskInfo>(a =>
  49. {
  50. a.Name("app_task");
  51. })
  52. //配置任务日志表
  53. .ConfigEntity<TaskLog>(a =>
  54. {
  55. a.Name("app_task_log");
  56. });
  57. };
  58. //模块任务处理器
  59. options.TaskHandler = new TaskHandler(options.FreeSql);
  60. });
  61. },
  62. //配置Autofac容器
  63. ConfigureAutofacContainer = (builder, context) =>
  64. {
  65. },
  66. //配置Mvc
  67. ConfigureMvcBuilder = (builder, context) =>
  68. {
  69. },
  70. //配置后置中间件
  71. ConfigurePostMiddleware = context =>
  72. {
  73. var app = context.App;
  74. var env = app.Environment;
  75. var appConfig = app.Services.GetService<AppConfig>();
  76. #region 新版Api文档
  77. if (env.IsDevelopment() || appConfig.ApiUI.Enable)
  78. {
  79. app.UseApiUI(options =>
  80. {
  81. options.RoutePrefix = appConfig.ApiUI.RoutePrefix;
  82. var routePath = options.RoutePrefix.NotNull() ? $"{options.RoutePrefix}/" : "";
  83. appConfig.Swagger.Projects?.ForEach(project =>
  84. {
  85. options.SwaggerEndpoint($"/{routePath}swagger/{project.Code.ToLower()}/swagger.json", project.Name);
  86. });
  87. });
  88. }
  89. #endregion
  90. }
  91. }).Run(args);
  92. #if DEBUG
  93. public partial class Program { }
  94. #endif