I don't know what I'm doing anymore
This commit is contained in:
parent
ea9cc32534
commit
8fdee0cb67
17 changed files with 342 additions and 116 deletions
|
@ -15,7 +15,9 @@ namespace SignalRChat
|
|||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
CreateHostBuilder(args).Build().Run();
|
||||
var host= CreateHostBuilder(args).Build();
|
||||
CreateDbIfNotExists(host);
|
||||
host.Run();
|
||||
}
|
||||
|
||||
public static IHostBuilder CreateHostBuilder(string[] args) =>
|
||||
|
@ -32,22 +34,22 @@ namespace SignalRChat
|
|||
// webBuilder.UseStartup<Startup>();
|
||||
// });
|
||||
|
||||
// private static void CreateDbIfNotExists(IHost host)
|
||||
// {
|
||||
// using (var scope = host.Services.CreateScope())
|
||||
// {
|
||||
// var services = scope.ServiceProvider;
|
||||
// try
|
||||
// {
|
||||
// var context = services.GetRequiredService<MyDbContext>();
|
||||
// DbInitializer.Initialize(context);
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// var logger = services.GetRequiredService<ILogger<Program>>();
|
||||
// logger.LogError(ex, "An error occurred creating the DB.");
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
private static void CreateDbIfNotExists(IHost host)
|
||||
{
|
||||
using (var scope = host.Services.CreateScope())
|
||||
{
|
||||
var services = scope.ServiceProvider;
|
||||
try
|
||||
{
|
||||
var context = services.GetRequiredService<MyDbContext>();
|
||||
DbInitializer.Initialize(context);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var logger = services.GetRequiredService<ILogger<Program>>();
|
||||
logger.LogError(ex, "An error occurred creating the DB.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue