private static void SeedDatabase(IHost host) { using var scope = host.Services.CreateScope(); var services = scope.ServiceProvider; var loggerFactory = services.GetRequiredService <ILoggerFactory>(); try { var aspnetRunContext = services.GetRequiredService <DemoContext>(); DemoContextSeed.SeedAsync(aspnetRunContext, loggerFactory).Wait(); } catch (Exception exception) { var logger = loggerFactory.CreateLogger <Program>(); logger.LogError(exception, "An error occurred seeding the DB."); } }
private static void SeedDatabase(IHost host) { using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; var loggerFactory = services.GetRequiredService <ILoggerFactory>(); try { var demoContext = services.GetRequiredService <DemoContext>(); DemoContextSeed.SeedAsync(demoContext, loggerFactory).Wait(); } catch (Exception exception) { var logger = loggerFactory.CreateLogger <Program>(); logger.LogError(exception, "Un Error ha ocurrido en la base de datos"); } } }