private static async Task InitializeDbAsync(IApplicationBuilder app) { using (IServiceScope serviceScope = app.ApplicationServices.GetService <IServiceScopeFactory>().CreateScope()) { ConfigStoreContext context = serviceScope.ServiceProvider.GetRequiredService <ConfigStoreContext>(); context.Database.SetCommandTimeout(TimeSpan.FromMinutes(5)); await context.Database.MigrateAsync(); ConfigClient client = serviceScope.ServiceProvider.GetRequiredService <ConfigClient>(); await client.ClearAsync(); DbInitializer initializer = new DbInitializer(context, client); await initializer.SeedAsync(); } }