You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
1.8 KiB
C#
60 lines
1.8 KiB
C#
using Autofac.Extensions.DependencyInjection;
|
|
using Autofac;
|
|
using DS.Module.AutofacModule;
|
|
using DS.Module.SqlSugar;
|
|
using DS.Module.UserModule;
|
|
using DS.Module.RedisModule;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using NLog.Web;
|
|
using DS.WMS.FeeBillRecvService;
|
|
|
|
|
|
var builder = Host.CreateApplicationBuilder(args);
|
|
|
|
builder.Services.AddWindowsService(options =>
|
|
{
|
|
options.ServiceName = ".NET Work Service";
|
|
});
|
|
//注册配置
|
|
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<IProblemDetailsWriter, SampleProblemDetailsWriter>();
|
|
//builder.Services.AddExceptionHandler<GlobalExceptionsFilter>(); //全局异常
|
|
builder.Services.AddControllers(options =>
|
|
{
|
|
options.Filters.Add<GlobalExceptionsFilter>();
|
|
});
|
|
builder.Services.AddUserModuleInstall(); //用户服务
|
|
builder.Services.AddRedisModuleInstall();//redis
|
|
builder.Services.AddSqlSugarInstall();
|
|
builder.Services.AddSaasDbInstall();//分库服务
|
|
|
|
//应用作为 Windows 服务
|
|
//builder.Services.AddWindowsService();
|
|
builder.Services.AddHostedService<RecvFeeBillWorker>();
|
|
|
|
|
|
|
|
//允许 BackgroundService 中存在未经处理的异常,不停止主机
|
|
builder.Services.Configure<HostOptions>(hostOptions =>
|
|
{
|
|
hostOptions.BackgroundServiceExceptionBehavior = BackgroundServiceExceptionBehavior.Ignore;
|
|
hostOptions.ServicesStartConcurrently = true;
|
|
hostOptions.ServicesStopConcurrently = true;
|
|
});
|
|
|
|
|
|
var host = builder.Build();
|
|
|
|
host.Run();
|