// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IServiceProvider services, GameSenseContext context, RoleManager <IdentityRole> roleManager, UserManager <User> userManager) { 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(); }); SeedUser.Initialize(context, userManager, roleManager).Wait(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, UserManager <AppUser> userManager) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); } else { app.UseExceptionHandler("/Home/Error"); app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseCookiePolicy(); app.UseAuthentication(); SeedUser.Initialize(userManager); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); }
public static void Main(string[] args) { // CreateHostBuilder(args).Build().Run(); var host = CreateWebHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var sp = scope.ServiceProvider; try { var context = sp.GetRequiredService <DataContext>(); var userManager = sp.GetRequiredService <UserManager <AppUser> >(); context.Database.Migrate(); SeedUser.Initialize(context, userManager).Wait(); SeedProducts.Initialize(context).Wait(); SeedVoucherCode.Initialize(context).Wait(); } catch (Exception err) { var logger = sp.GetRequiredService <ILogger <Program> >(); logger.LogError(err, "Error migrating database"); } } host.Run(); }
public static void Main(string[] args) { AppContext.SetSwitch("Switch.Microsoft.AspNetCore.Mvc.EnableRangeProcessing", true); // enable to send partial content var host = CreateWebHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; var context = services.GetRequiredService <ApplicationDbContext>(); context.Database.Migrate(); var config = host.Services.GetRequiredService <IConfiguration>(); var userEmail = config.GetSection("UserSettings")["UserEmail"]; var userPassword = config.GetSection("UserSettings")["UserPassword"]; try { SeedUser.Initialize(services, userEmail, userPassword).Wait(); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex.Message, "An error occurred seeding the DB."); } } host.Run(); }
public static void Main(string[] args) { var host = CreateWebHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var context = services.GetRequiredService <UserContext>(); context.Database.Migrate(); SeedUser.Initialize(services); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred seeding the DB."); } } host.Run(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseRouting(); app.UseCors("AllowAll"); app.UseAuthentication(); app.UseAuthorization(); //app.UseCors("AllowAll"); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); SeedUser.Initialize(app.ApplicationServices.GetRequiredService <IServiceScopeFactory>().CreateScope().ServiceProvider); }