protected static async Task SeedDb(DbContextOptions <MiniURLDbContext> dbOptions, IDateTime dateTime) { using (var ctx = new MiniURLDbContext(dbOptions, dateTime)) { var seeder = new MiniURLDbContextSeeder(ctx); try { await seeder.SeedAllAsync(new System.Threading.CancellationToken()); } catch (Exception ex) { throw ex; } } }
private async static Task SeedDb(IHost host) { using var scope = host.Services.CreateScope(); var services = scope.ServiceProvider; var ctx = services.GetRequiredService <IMiniURLDbContext>(); var seeder = new MiniURLDbContextSeeder(ctx); try { await seeder.SeedAllAsync(new System.Threading.CancellationToken()); } catch (Exception ex) { throw ex; } }