public void Configure(IApplicationBuilder app, IHostingEnvironment env, DatabaseSeeder seeder) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler(builder => { builder.Run(async context => { context.Response.StatusCode = (int)HttpStatusCode.InternalServerError; var error = context.Features.Get <IExceptionHandlerFeature>(); if (error != null) { context.Response.AddApplicationError(error.Error.Message); await context.Response.WriteAsync(error.Error.Message); } }); }); } seeder.SeedUsers(); app.UseCors(x => x.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod()); app.UseAuthentication(); app.UseMvc(); }
public static IWebHost SeedData(this IWebHost host) { using (var scope = host.Services.CreateScope()) { IServiceProvider services = scope.ServiceProvider; ShoppingDbContext context = services.GetService <ShoppingDbContext>(); UserManager <UserEntity> userManager = services.GetService <UserManager <UserEntity> >(); RoleManager <IdentityRole> roleManager = services.GetService <RoleManager <IdentityRole> >(); IConfiguration config = services.GetService <IConfiguration>(); DatabaseSeeder.SeedRoles(roleManager); DatabaseSeeder.SeedUsers(userManager, config); } return(host); }