Startup.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using System.Diagnostics;
  2. using Admin.NET.Plugin.AiDOP.Entity;
  3. using Admin.NET.Plugin.AiDOP.Entity.S0.Manufacturing;
  4. using Admin.NET.Plugin.AiDOP.Entity.S0.Sales;
  5. using Admin.NET.Plugin.AiDOP.Infrastructure;
  6. using Microsoft.AspNetCore.Builder;
  7. using Microsoft.AspNetCore.Hosting;
  8. using Microsoft.AspNetCore.Mvc;
  9. using Microsoft.Extensions.DependencyInjection;
  10. using Microsoft.Extensions.Hosting;
  11. using SqlSugar;
  12. namespace Admin.NET.Plugin.AiDOP;
  13. /// <summary>
  14. /// AiDOP 插件启动配置(按需扩展 DI)
  15. /// </summary>
  16. [AppStartup(900)]
  17. public class Startup : AppStartup
  18. {
  19. public void ConfigureServices(IServiceCollection services)
  20. {
  21. services.AddScoped<AdoS0ExceptionFilter>();
  22. services.AddScoped<AdoS0ResultFilter>();
  23. services.Configure<MvcOptions>(options =>
  24. {
  25. options.Filters.AddService<AdoS0ExceptionFilter>();
  26. options.Filters.AddService<AdoS0ResultFilter>();
  27. });
  28. }
  29. /// <summary>
  30. /// 开发环境下为 Demo 表执行 CodeFirst(表已存在则跳过变更,行为取决于 SqlSugar 配置)。
  31. /// </summary>
  32. public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
  33. {
  34. try
  35. {
  36. AidopMenuLinkSync.EnsureLinked(app.ApplicationServices);
  37. }
  38. catch (Exception ex)
  39. {
  40. Trace.TraceWarning("Ai-DOP AidopMenuLinkSync: " + ex);
  41. }
  42. if (!env.IsDevelopment())
  43. return;
  44. using var scope = app.ApplicationServices.CreateScope();
  45. var db = scope.ServiceProvider.GetRequiredService<ISqlSugarClient>();
  46. db.CodeFirst.InitTables(
  47. typeof(AdoOrder),
  48. typeof(AdoPlan),
  49. typeof(AdoWorkOrder),
  50. typeof(AdoS0Customer),
  51. typeof(AdoS0Material),
  52. typeof(AdoS0OrderPriorityRule),
  53. typeof(AdoS0MfgBom),
  54. typeof(AdoS0MfgBomItem),
  55. typeof(AdoS0MfgStandardOperation),
  56. typeof(AdoS0MfgProductionLine),
  57. typeof(AdoS0MfgRouting),
  58. typeof(AdoS0MfgRoutingOperation),
  59. typeof(AdoS0MfgPersonSkillAssignment),
  60. typeof(AdoS0MfgMaterialSubstitution),
  61. typeof(AdoS0MfgWorkOrderControl),
  62. typeof(AdoS0MfgPersonSkill),
  63. typeof(AdoS0MfgLinePost),
  64. typeof(AdoS0MfgLinePostSkill),
  65. typeof(AdoS0MfgWorkCenter),
  66. typeof(AdoS0MfgLineMaterial),
  67. typeof(AdoS0MfgElementParam),
  68. typeof(AdoS0MfgMaterialProcessElement),
  69. typeof(AdoS0MfgPreprocessElement),
  70. typeof(AdoS0MfgPreprocessElementParam),
  71. typeof(AdoS0MfgSopFileType),
  72. typeof(AdoS0MfgSopDocument)
  73. );
  74. }
  75. }