[backend] feat: Add database initialization

This commit is contained in:
ChronosX88 2019-09-26 01:50:17 +04:00
parent b2703ab1d6
commit 1025dee279
Signed by: ChronosXYZ
GPG Key ID: 085A69A82C8C511A

View File

@ -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<IServiceScopeFactory>();
using (var serviceScope = serviceScopeFactory.CreateScope())
{
var dbContext = serviceScope.ServiceProvider.GetService<DatabaseContext>();
dbContext.Database.EnsureCreated();
}
}
}
}