Ejemplo n.º 1
0
        public static async Task Main(string[] args)
        {
            // outside of middleware in the Main method
            var host = CreateHostBuilder(args).Build();

            using var scope = host.Services.CreateScope(); // creating a scope for the services
            var services = scope.ServiceProvider;

            try
            {
                var context     = services.GetRequiredService <DataContext>();
                var userManager = services.GetRequiredService <UserManager <AppUser> >();
                var roleManager = services.GetRequiredService <RoleManager <AppRole> >();

                await context.Database.MigrateAsync();

                await Seed.SeedAdmins(userManager, roleManager);

                await Seed.AddGamesAndTypes(context);
            }
            catch (Exception ex)
            {
                var logger = services.GetRequiredService <ILogger <Program> >();
                logger.LogError(ex, "An error occurred during migration.");
            }

            await host.RunAsync();
        }