using DS.WMS.JobService; using DS.Module.HangfireModule; using Autofac.Extensions.DependencyInjection; using Autofac; using DS.Module.AutofacModule; using DS.Module.SqlSugar; using DS.Module.UserModule; using DS.Module.RedisModule; using Hangfire; using DS.WMS.Core.HangfireJob.Interface; using DS.WMS.Core.HangfireJob.Method; using Microsoft.AspNetCore.Http; using NLog.Web; var builder = Host.CreateApplicationBuilder(args); //应用作为 Windows 服务 builder.Services.AddWindowsService(); //注册配置 builder.Configuration .AddJsonFile(path: "appsettings.json", optional: false, reloadOnChange: true) .Build(); builder.Configuration.AddEnvironmentVariables(); builder.Logging.AddNLog("nlog.config"); //Autofac注入 builder.ConfigureContainer(new AutofacServiceProviderFactory(), builder => builder.RegisterModule(new AutofacModuleRegister())); builder.Services.AddTransient(); //builder.Services.AddExceptionHandler(); //全局异常 builder.Services.AddControllers(options => { options.Filters.Add(); }); builder.Services.AddUserModuleInstall(); //用户服务 builder.Services.AddRedisModuleInstall();//redis builder.Services.AddSqlSugarInstall(); builder.Services.AddSaasDbInstall();//分库服务 //注入hangfire builder.Services.AddWorkServiceHangfireModuleInstall(); builder.Services.AddHostedService(); //允许 BackgroundService 中存在未经处理的异常,不停止主机 builder.Services.Configure(hostOptions => { hostOptions.BackgroundServiceExceptionBehavior = BackgroundServiceExceptionBehavior.Ignore; }); var host = builder.Build(); host.Run();