Beispiel #1
0
        public static async Task SeedDatabase(IHost host)
        {
            using var scope = host.Services.CreateScope();
            var services = scope.ServiceProvider;

            try
            {
                var context     = services.GetRequiredService <AppDbContext>();
                var userManager = services.GetRequiredService <UserManager <AppUser> >();

                await context.Database.MigrateAsync();

                await AppDbContextSeed.SeedData(context, userManager);
            }
            catch (Exception ex)
            {
                var logger = services.GetRequiredService <ILogger <Program> >();
                logger.LogError(ex, "An error occurred while migrating or seeding the database.");
            }
        }