Exemplo n.º 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();
            });
        }
Exemplo n.º 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();
        }
Exemplo n.º 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
            }
        }
Exemplo n.º 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
            }
        }
Exemplo n.º 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) { }
            }
        }
Exemplo n.º 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();
        }