Exemple #1
0
 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();
     }
 }
Exemple #2
0
        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();
            }
        }