示例#1
0
        public static void Main(string[] args)
        {
            var host = CreateWebHostBuilder(args).Build();

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

                try
                {
                    var roleManager     = scope.ServiceProvider.GetService <RoleManager <IdentityRole> >();
                    var userManager     = scope.ServiceProvider.GetService <UserManager <AppUser> >();
                    var identityContext = scope.ServiceProvider.GetRequiredService <AppIdentityContext>();
                    var productContext  = services.GetRequiredService <ProductContext>();

                    identityContext.Database.Migrate();
                    IdentitySeedData.EnsurePopulated(identityContext, roleManager, userManager);

                    productContext.Database.Migrate();
                    ProductSeedData.EnsurePopulated(productContext, identityContext);
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occurred seeding the DB.");
                }
            }

            host.Run();
        }
示例#2
0
        public static async void UseSportsStore(this IApplicationBuilder app)
        {
            await Migrate.ExecuteContextsMigrate(app);

            await DictionarySeedData.PopulateDictionaries(app);

            await ProductSeedData.EnsurePopulated(app);

            await PermissionSeedData.PopulatePermissions(app);

            await IdentitySeedData.PopulateIdentity(app);

            await SystemParametersSeedData.PopulateParameters(app);
        }
示例#3
0
 public IActionResult SeedDatabase()
 {
     ProductSeedData.EnsurePopulated(HttpContext.RequestServices);
     return(RedirectToAction(nameof(Index)));
 }