Exemplo n.º 1
0
        public static void 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 <AppUser> >();
                    context.Database.Migrate();
                    Seed.SeedData(context, userManager).Wait();

                    var serviceProvider = services.GetRequiredService <IServiceProvider>();

                    Seed.CreateRoles(serviceProvider, "Admin", "*****@*****.**").Wait();
                    Seed.CreateRoles(serviceProvider, "Supplier").Wait();
                    Seed.CreateRoles(serviceProvider, "Reseller").Wait();

                    //Seed.AddRoles(serviceProvider, "Admin", "*****@*****.**").Wait();
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occured during migration");
                }
            }

            host.Run();
        }