public static async Task Main(string[] args) { var host = CreateHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var context = services.GetRequiredService <SupportPlatformDbContext>(); var userManager = services.GetRequiredService <UserManager <UserEntity> >(); var roleManager = services.GetRequiredService <RoleManager <RoleEntity> >(); await context.Database.MigrateAsync(); await UserSeeder.SeedUsers(userManager, roleManager); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occured during migration"); } } await host.RunAsync(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, UserManager <User> userManager) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseFileServer(); app.UseAuthentication(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Account}/{action=Index}"); routes.MapRoute( name: "shipDetails", template: "Dashboard/Details/{shipId}", defaults: new { controller = "Dashboard", action = "Details" }); }); UserSeeder.SeedUsers(userManager); ShipSeeder.SeedShips(); KpiSeeder.SeedKpis(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, UserManager <WebShopUser> userManager, RoleManager <IdentityRole <Guid> > roleManager, WebShopDbContext context) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } 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.UseAuthentication(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); endpoints.MapRazorPages(); endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); }); //TODO: So ugly, debug thread issue with dbcontext error in SeedUsers UserSeeder.SeedUsers(userManager, roleManager, context).Wait(); }