public static void Main(string[] args) { var host = CreateHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var context = services.GetRequiredService <DataContext>(); var roleManager = services.GetRequiredService <RoleManager <Role> >(); var userManager = services.GetRequiredService <UserManager <ApplicationUser> >(); context.Database.Migrate(); var dataSeeder = new DataSeeder(context, roleManager, userManager); dataSeeder.Initialize().Wait(); } 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, PortalDbContext dbContext) { 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.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); }); DataSeeder.Initialize(dbContext); }
public static void Main(string[] args) { var host = CreateWebHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; var context = services.GetRequiredService <CustomContext>(); try { DataSeeder.Initialize(services); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred seeding the DB."); } } host.Run(); // CreateWebHostBuilder(args).Build().Run(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public async void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IServiceProvider serviceProvider, ModelDbContext context) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); app.UseBrowserLink(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseStaticFiles(); app.UseIdentity(); // Add external authentication middleware below. To configure them please see http://go.microsoft.com/fwlink/?LinkID=532715 app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); await CreateRoles(serviceProvider); DataSeeder.Initialize(context); }
public static async Task Main(string[] args) { var host = CreateHostBuilder(args).Build(); await DataSeeder.Initialize(host); 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) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { // 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.UseMvc(); app.UseSwagger(); app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1"); }); using (var scope = app.ApplicationServices.GetRequiredService <IServiceScopeFactory>().CreateScope()) { var services = scope.ServiceProvider; DataSeeder.Initialize(services); } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ApplicationDbContext context, RoleManager <ApplicationRole> roleManager, UserManager <ApplicationUser> userManager) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); } else { app.UseExceptionHandler("/Home/Error"); app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseCookiePolicy(); app.UseSession(); app.UseAuthentication(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); DataSeeder.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, IWebHostEnvironment env) { var sp = app.ApplicationServices; using (var scope = sp.CreateScope()) { var dbContext = scope.ServiceProvider.GetService <WebApiDbContext>(); DataSeeder.Initialize(dbContext); } if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseHttpsRedirection(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); }
public static void Main(string[] args) { var host = CreateHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; var context = services.GetRequiredService <PMContext>(); DataSeeder.Initialize(services); } host.Run(); }
public static void Main(string[] args) { var host = CreateWebHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; DataSeeder.Initialize(services); } 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, UserManager <Employee> userManager, IDataContext context, RoleManager <IdentityRole> roleManager) { //if (env.IsDevelopment()) //{ // app.UseDeveloperExceptionPage(); // //app.UseDatabaseErrorPage(); //} //else //{ // app.UseExceptionHandler("/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(); if (!env.IsDevelopment()) { app.UseSpaStaticFiles(); } app.UseRouting(); app.UseAuthentication(); //app.UseIdentityServer(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); //endpoints.MapControllerRoute( // name: "default", // pattern: "{controller}/{action}/{id?}"); //endpoints.MapRazorPages(); }); app.UseSpa(spa => { // To learn more about options for serving an Angular SPA from ASP.NET Core, // see https://go.microsoft.com/fwlink/?linkid=864501 spa.Options.SourcePath = "ClientApp"; if (env.IsDevelopment()) { spa.UseAngularCliServer(npmScript: "start"); } }); DataSeeder.Initialize(userManager, context, roleManager); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, UserManager <IdentityUser> userManager, RoleManager <IdentityRole> roleManager) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/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.UseSpaStaticFiles(); app.UseAuthentication(); app.UseSignalR(routes => { routes.MapHub <ServerHub>("/serverHub"); }); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller}/{action=Index}/{id?}"); }); app.UseSpa(spa => { spa.Options.SourcePath = "ClientApp"; if (env.IsDevelopment()) { //spa.UseReactDevelopmentServer(npmScript: "start"); spa.UseProxyToSpaDevelopmentServer("http://localhost:3000"); } }); DataSeeder.Initialize(roleManager, userManager).Wait(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ApplicationDbContext appDbContext, LogDbContext logDbContext) { try { // appDbContext.Database.EnsureDeleted(); appDbContext.Database.EnsureCreated(); DataSeeder.Initialize(appDbContext); logDbContext.Database.EnsureCreated(); } catch (Exception ex) { var e = ex; Console.WriteLine("An error occurred while seeding the database."); } 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.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); app.UseMiddleware <LogMiddleware>(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); endpoints.MapControllerRoute( name: "account", pattern: "{controller=Account}/{action=Index}/{id?}"); }); }
public static void Main(string[] args) { IWebHost host = CreateWebHostBuilder(args).Build(); using (IServiceScope scope = host.Services.CreateScope()) { IServiceProvider services = scope.ServiceProvider; try { ApplicationDbContext context = services.GetRequiredService <ApplicationDbContext>(); DataSeeder.Initialize(context); } catch (Exception) { Console.WriteLine("An error occurred while seeding the database."); } } host.Run(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseHsts(); } //Allow CORS to the specific ploicy app.UseCors(AllowSpecificOriginsPolicy); app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseMvc(); //Seeds data which sotred in json file inside the data folder to database DataSeeder.Initialize(app); }
public static void Main(string[] args) { // CreateHostBuilder(args).Build().Run(); //1. Get the IWebHost which will host this application. var host = CreateHostBuilder(args).Build(); //2. Find the service layer within our scope. using (var scope = host.Services.CreateScope()) { //3. Get the instance of BoardGamesDBContext in our services layer var services = scope.ServiceProvider; var context = services.GetRequiredService <ApplicationDBContext>(); //4. Call the DataGenerator to create sample data DataSeeder.Initialize(services); } //Continue to run the application host.Run(); }
public static void Main(string[] args) { var logger = NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger(); try { logger.Debug("init main"); var host = BuildWebHost(args); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; var context = services.GetRequiredService <MBoxDbContext>(); try { DataSeeder.Initialize(services); } catch (Exception ex) { var loggerLocal = services.GetRequiredService <ILogger <Program> >(); loggerLocal.LogError(ex, "An error occurred seeding the DB."); } } host.Run(); } catch (Exception ex) { //NLog: catch setup errors logger.Error(ex, "Stopped program because of exception"); throw; } finally { // Ensure to flush and stop internal timers/threads before application-exit (Avoid segmentation fault on Linux) NLog.LogManager.Shutdown(); } }
public static void Main(string[] args) { //the seeding routine is from here: https://docs.microsoft.com/en-us/aspnet/core/tutorials/first-mvc-app-xplat/working-with-sql?view=aspnetcore-2.0 //this should change in 2.1 var host = BuildWebHost(args); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { DataSeeder.Initialize(services); } catch (Exception exp) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(exp, "An error occurred seeding the Database"); } } host.Run(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ApplicationDbContext context, RoleManager <ApplicationRole> roleManager, UserManager <User> userManager) { var supportedCultures = new[] { new CultureInfo("en-GB") }; app.UseRequestLocalization(new RequestLocalizationOptions { DefaultRequestCulture = new RequestCulture("en-GB"), SupportedCultures = supportedCultures, SupportedUICultures = supportedCultures }); 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.UseCookiePolicy(); app.UseAuthentication(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); DataSeeder.Initialize(context, userManager, roleManager).Wait();// seed here }
public static void Init() { DataSeeder.Initialize(); }