public static void Main(string[] args) { Log.Logger = new LoggerConfiguration() .Enrich.FromLogContext() .WriteTo.Console() .CreateLogger(); try { Log.Information("Starting up"); var host = CreateHostBuilder(args).Build(); using var scope = host.Services.CreateScope(); using var appContext = scope.ServiceProvider .GetRequiredService <PrateleiraLivrosContext>(); appContext.Database.Migrate(); PrateleiraLivrosContextSeed.SeedAsync(appContext) .ConfigureAwait(false); host.Run(); } catch (Exception ex) { Log.Fatal(ex, "Application start-up failed"); } finally { Log.CloseAndFlush(); } }
protected async Task <EfRepository <T> > GetRepository(bool seed = false) { var options = CreateNewContextOptions(); DbContext = new PrateleiraLivrosContext(options); if (seed) { await PrateleiraLivrosContextSeed .SeedAsync(DbContext); } return(new EfRepository <T>(DbContext)); }