• 周五. 1 月 3rd, 2025

5G编程聚合网

5G时代下一个聚合的编程学习网

热门标签

初始化的问题

admin

11 月 28, 2021

有一些服务启动需要在网站启动前执行完。比如说加载数据缓存。等等。

public static async Task Main(string[] args)
{
var config = new ConfigurationBuilder()
.AddJsonFile(“appsettings.json”, true, true)
.AddCommandLine(args)
.Build();

Log.Logger = new LoggerConfiguration()
.ReadFrom.Configuration(config)
.CreateLogger();

var currenthost = CreateHostBuilder(args).UseSerilog().Build();
using (var scope = currenthost.Services.CreateScope())
{
var sysdatamodelservice = scope.ServiceProvider.GetRequiredService<SysDataModelService>();
await sysdatamodelservice?.InitDataAsync();

var _WebSetService = scope.ServiceProvider.GetRequiredService<WebSetService>();
await _WebSetService?.InitDataAsync();
CustomerConfig.Instance.HttpServerUrl = _WebSetService.GetWebSettings().WebUrl;
var _WebMenuService = scope.ServiceProvider.GetRequiredService<WebMenuService>();
await _WebMenuService?.InitDataAsync();

//await myDbContext.Database.MigrateAsync();
}
//currenthost.Services.CreateScope()
currenthost.Run();
}

像这样。

发表回复