Create database at application startup
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user