Пример #1
0
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, SeedDb seeder)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                app.UseHsts();
            }
            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseRouting();
            app.UseAuthentication();
            app.UseAuthorization();

            seeder.SeedAsync().Wait();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");
                endpoints.MapRazorPages();
            });
        }
Пример #2
0
        private static void RunSeeding(IHost host)
        {
            IServiceScopeFactory scopeFactory = host.Services.GetService <IServiceScopeFactory>();

            using IServiceScope scope = scopeFactory.CreateScope();
            SeedDb seeder = scope.ServiceProvider.GetService <SeedDb>();

            seeder.SeedAsync().Wait();
        }
Пример #3
0
        private static void RunSeeding(IWebHost host)
        {
            var scopeFactory = host.Services.GetService <IServiceScopeFactory>();

            using (var scope = scopeFactory.CreateScope())
            {
                SeedDb seeder = scope.ServiceProvider.GetService <SeedDb>();
                seeder.SeedAsync().Wait(); //Wait till data is added to DB for Testing
            }
        }
Пример #4
0
        private static void RunSeeding(IWebHost host)
        {
            IServiceScopeFactory scopeFactory = host.Services.GetService <IServiceScopeFactory>();

            using (IServiceScope scope = scopeFactory.CreateScope())
            {
                SeedDb seeder = scope.ServiceProvider.GetService <SeedDb>();
                seeder.SeedAsync().Wait(); //Wait, permite correr un mètodo no async en async
            }
        }
Пример #5
0
        private static void RunSeeding(IWebHost host)
        {
            IServiceScopeFactory scopeFactory = host.Services.GetService <IServiceScopeFactory>();

            using (IServiceScope scope = scopeFactory.CreateScope())
            {
                SeedDb seeder = scope.ServiceProvider.GetService <SeedDb>();
                try { seeder.SeedAsync().Wait(); } catch (Exception) { }
            }
        }
Пример #6
0
        public static void Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                try
                {
                    var recipesDbContext = scope.ServiceProvider.GetRequiredService <RecipesDbContext>();
                    var userManager      = scope.ServiceProvider.GetRequiredService <UserManager <AppUser> >();
                    recipesDbContext.Database.Migrate();
                    SeedDb.SeedAsync(recipesDbContext, userManager).Wait();
                }
                catch (Exception ex)
                {
                    scope.ServiceProvider.GetRequiredService <ILogger>().LogError(ex, "Error running the app");
                }
            }

            host.Run();
        }