public static void Main(string[] args) { var host = BuildWebHost(args); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { WebStoreContext context = services.GetRequiredService <WebStoreContext>(); DbInitializer.Initialize(context); DbInitializer.InitializeUsers(services); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, message: "Oops... Something went wrong..."); } } host.Run(); }
public static void Main(string[] args) { var host = BuildWebHost(args); using (var scope = host.Services.CreateScope()) // нужно для получения DbContext { var services = scope.ServiceProvider; var context = services.GetRequiredService <WebStoreContext>(); try { DbInitializer.Initialize(context); DbInitializer.InitializeUsers(services); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger>(); logger.LogError(ex, "OOps. Something went wrong..."); } } host.Run(); }