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 <DataContext>();
                var userManager = services.GetRequiredService <UserManager <User> >();
                var roleManager = services.GetRequiredService <RoleManager <Role> >();
                await context.Database.MigrateAsync();

                await Seed.SeedRoles(roleManager);

                await Seed.AddAdminUser(userManager, roleManager);

                await Seed.SeedCollections(context);

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

            await host.RunAsync();
        }