// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, RoleManager <IdentityRole> roleMgr, UserManager <IdentityUser> userMgr, ApplicationDbContext dbContext) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); } else { app.UseExceptionHandler("/Home/Error"); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); endpoints.MapRazorPages(); }); //seeden van users en roles ApplicationDbContextExtensions.SeedData(dbContext).Wait(); ApplicationDbContextExtensions.SeedRolesAsync(roleMgr).Wait(); ApplicationDbContextExtensions.SeedUsersAsync(userMgr).Wait(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IServiceProvider serviceProvider, ApplicationDbContext context) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Error"); app.UseHsts(); } app.UseHttpsRedirection(); app.UseRouting(); app.UseAuthorization(); app.UseAuthentication(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); //configuratie openAPI documentatie app.UseSwagger(); app.UseSwaggerUI(c => { c.RoutePrefix = "swagger"; c.SwaggerEndpoint("/swagger/v1.0/swagger.json", "Security_API v1.0"); }); //cors opzetten app.UseCors("CorsPolicy"); //app.UseMvc(); //Seeder voor Identity & Data --------------------------------------------------------- //1. roleManager en userManager ophalen. var roleManager = serviceProvider.GetRequiredService <RoleManager <IdentityRole> >(); var userManager = serviceProvider.GetRequiredService <UserManager <IdentityUser> >(); //2. Seeder oproepen context.SeedData().Wait(); //Educations , oproepen als extensiemethode ApplicationDbContextExtensions.SeedRolesAsync(roleManager).Wait(); //zonder wait breekt de Task ApplicationDbContextExtensions.SeedUsersAsync(userManager).Wait(); }