Create database at application startup

This commit is contained in:
2020-03-05 19:45:14 +01:00
parent 41187c32d6
commit d8035452d8
2 changed files with 5 additions and 1 deletions

View File

@@ -74,6 +74,11 @@ namespace EstusShots.Server
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints => { endpoints.MapControllers(); });
// Open a scope and create the database, if necessary
using var scope = app.ApplicationServices.GetRequiredService<IServiceScopeFactory>().CreateScope();
using var context = scope.ServiceProvider.GetService<EstusShotsContext>();
context.Database.EnsureCreated();
}
}
}