public AccountController(UserManager <IdentityUser> userManager, SignInManager <IdentityUser> signInManager) { _userManager = userManager; _signInManager = signInManager; SeedIdentityData.EnsurePopulated(userManager).Wait(); }
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 <IdentityContext>(); context.Database.Migrate(); SeedIdentityData.Initialize(services); SeedData.Initialize(services); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred seeding the DB."); } } host.Run(); }
public void Configure(IApplicationBuilder app, IHostingEnvironment env) { SeedData.EnsurePopulated(app); SeedIdentityData.EnsurePopulated(app); app.UseDeveloperExceptionPage(); app.UseStaticFiles(); app.UseStatusCodePages(); app.UseAuthentication(); app.UseMvcWithDefaultRoute(); }
public static async Task Main(string[] args) { var host = CreateHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var serviceProvider = scope.ServiceProvider; var userManager = serviceProvider.GetRequiredService <UserManager <IdentityUser> >(); var seedIdentity = new SeedIdentityData(userManager); await seedIdentity.SeedUsers(); } 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.IsProduction()) { app.UseExceptionHandler("/error"); } else { app.UseDeveloperExceptionPage(); app.UseStatusCodePages(); } app.UseStaticFiles(); app.UseSession(); app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute("ArticleTypepage", "{ArticleType:int}/Page{ArticlePage:int}", new { Controller = "Home", action = "Index" }); endpoints.MapControllerRoute("page", "Page{ArticlePage:int}", new { Controller = "Home", action = "Index", ArticlePage = 1 }); endpoints.MapControllerRoute("ArticleType", "{ArticleType}", new { Controller = "Home", action = "Index", ArticlePage = 1 }); endpoints.MapControllerRoute("pagination", "Articles/{ArticlePage:int}", new { Controller = "Home", action = "Index", ArticlePage = 1 }); endpoints.MapDefaultControllerRoute(); endpoints.MapRazorPages(); endpoints.MapBlazorHub(); endpoints.MapFallbackToPage("/admin/{*catchall}", "/Admin/Index"); }); SeedData.Seed(app); SeedIdentityData.EnsurePopulated(app); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { app.UseCors("default"); if (env.IsDevelopment()) { app.UseBrowserLink(); app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); SeedIdentityData.InitializeDatabase(app); } else { app.UseExceptionHandler("/Home/Error"); } app.UseStaticFiles(); app.UseIdentityServer(); app.UseMvcWithDefaultRoute(); }
public static int Main(string[] args) { GlobalLogger.ConfigureLog(); try { var seed = args.Contains("/seed"); if (seed) { args = args.Except(new[] { "/seed" }).ToArray(); } var host = CreateHostBuilder(args).Build(); //if (seed) if (true) { Log.Information("Seeding database..."); var config = host.Services.GetRequiredService <IConfiguration>(); var connectionString = config.GetConnectionString("DefaultConnection"); //SeedData.EnsureSeedData(connectionString); SeedIdentityData.EnsureSeedData(connectionString); SeedIDPData.EnsureSeedData(connectionString); Log.Information("Done seeding database."); //return 0; } Log.Information("Starting host..."); host.Run(); return(0); } catch (Exception ex) { Log.Fatal(ex, "Host terminated unexpectedly."); return(1); } //finally //{ // Log.CloseAndFlush(); //} }
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 <ApplicationDbContext>(); await context.Database.MigrateAsync(); await SeedInitialData.SeedAuthorsDataAsync(context); await SeedInitialData.SeedCategoriesDataAsync(context); await SeedInitialData.SeedBooksDataAsync(context); // Identity var userManager = services.GetRequiredService <UserManager <AppUser> >(); var roleManager = services.GetRequiredService <RoleManager <IdentityRole> >(); var identityContext = services.GetRequiredService <AppIdentityDbContext>(); var config = services.GetRequiredService <IConfiguration>(); await identityContext.Database.MigrateAsync(); await SeedIdentityData.SeedUsersAndRolesAsync(userManager, roleManager, config); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred during data seeding"); } } await host.RunAsync(); }
public static void Main(string[] args) { //CreateWebHostBuilder(args).Build().Run(); var host = CreateWebHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var serviceProvider = services.GetRequiredService <IServiceProvider>(); var configuration = services.GetRequiredService <IConfiguration>(); SeedIdentityData.CreateRoles(serviceProvider, configuration).Wait(); } catch (Exception exception) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(exception, "An error occurred while creating roles"); } } using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var context = new ApplicationDbContext(); SeedQuizData.CreateDemoQuiz(context).Wait(); context.Dispose(); } catch (Exception exception) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(exception, "An error occurred while creating demo quiz"); } } host.Run(); }