From 1025dee27952561f646bf1c64065128cf49f08fd Mon Sep 17 00:00:00 2001 From: ChronosX88 Date: Thu, 26 Sep 2019 01:50:17 +0400 Subject: [PATCH] [backend] feat: Add database initialization --- Startup.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Startup.cs b/Startup.cs index e4b5557..515a4f2 100644 --- a/Startup.cs +++ b/Startup.cs @@ -32,8 +32,6 @@ namespace InstructorsListApp { configuration.RootPath = "ClientApp/dist"; }); - - } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. @@ -73,6 +71,14 @@ namespace InstructorsListApp spa.UseProxyToSpaDevelopmentServer("http://localhost:4200"); } }); + + // initialize database + var serviceScopeFactory = app.ApplicationServices.GetRequiredService(); + using (var serviceScope = serviceScopeFactory.CreateScope()) + { + var dbContext = serviceScope.ServiceProvider.GetService(); + dbContext.Database.EnsureCreated(); + } } } }