using Autofac; using Autofac.Extensions.DependencyInjection; using DS.Module.AutofacModule; using DS.Module.HangfireModule; using DS.Module.RedisModule; using DS.Module.SqlSugar; using DS.Module.UserModule; using DS.WMS.JobServiceApi; using NLog.Web; var builder = WebApplication.CreateBuilder(args); //注册配置 builder.Configuration .AddJsonFile(path: "appsettings.json", optional: false, reloadOnChange: true) .Build(); builder.Configuration.AddEnvironmentVariables(); builder.Logging.AddNLog("nlog.config"); // Add services to the container. //Autofac注入 builder.Host .UseServiceProviderFactory(new AutofacServiceProviderFactory()) .ConfigureContainer(builder => { builder.RegisterModule(new AutofacModuleRegister()); }); builder.Services.AddUserModuleInstall(); //用户服务 builder.Services.AddRedisModuleInstall();//redis builder.Services.AddSqlSugarInstall(); builder.Services.AddSaasDbInstall();//分库服务 builder.Services.AddWorkServiceHangfireModuleInstall();//Hangfire服务 //允许 BackgroundService 中存在未经处理的异常,不停止主机 builder.Services.Configure(hostOptions => { hostOptions.BackgroundServiceExceptionBehavior = BackgroundServiceExceptionBehavior.Ignore; }); //应用作为 Windows 服务 builder.Services.AddWindowsService(); var app = builder.Build(); //app.UseHangfireMiddleware(); //异常中间件 app.UseMiddleware(); //app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); app.Run();