有一些服务启动需要在网站启动前执行完。比如说加载数据缓存。等等。
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();
}
像这样。