public static async Task EnsureSeedData(IApplicationBuilder app) { using (var serviceScope = app.ApplicationServices.GetService <IServiceScopeFactory>().CreateScope()) { var dbContext = serviceScope.ServiceProvider.GetRequiredService <AuthorizeDbContext>(); var authPermissions = serviceScope.ServiceProvider.GetRequiredService <IAuthPermissions>(); AuthorizeDbContextSeed.SeedDefaultAsync(dbContext, authPermissions); await dbContext.SaveChangesAsync(); } }
public static async Task EnsureSeedData(IHost host) { using (var serviceScope = host.Services.CreateScope()) { var dbContext = serviceScope.ServiceProvider.GetRequiredService <AuthorizeDbContext>(); await dbContext.Database.EnsureCreatedAsync(); var authPermissions = serviceScope.ServiceProvider.GetRequiredService <IAuthPermissions>(); AuthorizeDbContextSeed.SeedDefaultAsync(dbContext, authPermissions); await dbContext.SaveChangesAsync(); } }