Exemple #1
0
        public static IApplicationBuilder SeedDatabase(this IApplicationBuilder app, DefaultUser user)
        {
            var serviceProvider = app.ApplicationServices.CreateScope().ServiceProvider;

            try
            {
                var roleManager = serviceProvider.GetService <RoleManager <Role> >();
                var userManager = serviceProvider.GetService <UserManager <User> >();

                DatabaseSeeder.InsertSeedData(userManager, roleManager, user);
            }
            catch (Exception)
            {
            }
            return(app);
        }
Exemple #2
0
        public static IApplicationBuilder SeedDatabase(this IApplicationBuilder app)
        {
            IServiceProvider serviceProvider = app.ApplicationServices.CreateScope().ServiceProvider;

            try
            {
                var context = serviceProvider.GetService <EShopContext>();
                DatabaseSeeder.InsertSeedData(context);
            }
            catch (Exception ex)
            {
                var logger = serviceProvider.GetRequiredService <ILogger <Program> >();
                logger.LogError(ex, "An error occurred while seeding the database.");
            }
            return(app);
        }