Exemplo n.º 1
0
        public static async Task Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            using var scope = host.Services.CreateScope();
            var services = scope.ServiceProvider;

            try
            {
                var context = services.GetRequiredService <ApplicationDbContext>();
                await context.Database.MigrateAsync();

                var userManager = services.GetRequiredService <UserManager <Account> >();
                var roleManager = services.GetRequiredService <RoleManager <AppRole> >();
                await AuthorSeed.SeedAuthor(context);

                await BookSeed.SeedBooks(context);

                await UserSeed.SeedUsers(userManager, roleManager);
            }
            catch (Exception ex)
            {
                var logger = services.GetRequiredService <ILogger <Program> >();
                logger.LogError(ex, "An error occurred during migration");
            }

            await host.RunAsync();
        }