public static void Main(string[] args) { var host = CreateWebHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var env = host.Services.GetService <IHostingEnvironment>(); if (env.IsDevelopment()) { var services = scope.ServiceProvider; try { var ctx1 = services.GetRequiredService <AppDbContext>(); ctx1.Database.Migrate(); AppDbInitializer.Initialize(ctx1); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred creating the DB."); throw; } } } 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, ILoggerFactory loggerFactory) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseBrowserLink(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseStaticFiles(); app.UseMvc(routes => { routes.MapRoute( name: "areaRoute", template: "{area:exists}/{controller=Home}/{action=Index}/{id?}"); routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); AppDbInitializer.Initialize(app.ApplicationServices.GetService <AppDbContext>()); }
public static void Main(string[] args) { var host = BuildWebHost(args); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; var logger = services.GetRequiredService <ILogger <Program> >(); try { var context = services.GetRequiredService <AspergillosisContext>(); var context2 = services.GetRequiredService <ApplicationDbContext>(); var hostingEnvironment = services.GetRequiredService <IHostingEnvironment>(); AspergillosisDatabaseSeeder.SeedDatabase(hostingEnvironment, context); AppDbInitializer.Initialize(context2); } catch (Exception ex) { logger.LogError(ex, "An error occurred while seeding the database."); } finally { } } 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, ILoggerFactory loggerFactory) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); app.UseApplicationInsightsRequestTelemetry(); if (env.IsDevelopment()) { app.UseBrowserLink(); app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); } else { app.UseExceptionHandler("/Order/Error"); // For more details on creating database during deployment see http://go.microsoft.com/fwlink/?LinkID=615859 try { using (var serviceScope = app.ApplicationServices.GetRequiredService <IServiceScopeFactory>() .CreateScope()) { serviceScope.ServiceProvider.GetService <ApplicationDbContext>() .Database.Migrate(); } } catch { } } app.UseIISPlatformHandler(options => options.AuthenticationDescriptions.Clear()); app.UseApplicationInsightsExceptionTelemetry(); app.UseStaticFiles(); app.UseIdentity(); app.UseSession(); // To configure external authentication please see http://go.microsoft.com/fwlink/?LinkID=532715 app.UseGoogleAuthentication(options => { options.ClientId = "450267970917-qf25gkmpjqe177t8c1jfu78dtdgs5p30.apps.googleusercontent.com"; options.ClientSecret = "Xyc5VhAJX8SWLxffocOpT13C"; }); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Order}/{action=Index}/{id?}"); }); AppDbInitializer.Initialize(app.ApplicationServices); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IAppDbContext dataContext) { AppDbInitializer.Initialize(dataContext); loggerFactory.AddNLog(); app.AddNLogWeb(); app.UseMiddleware(typeof(ExceptionHandlingMiddleware)); app.UseMvc(); var cpuMonitorUnitOfWork = new UnitOfWork(dataContext); var cpuMonitor = new CpuMonitor(loggerFactory.CreateLogger <CpuMonitor>(), cpuMonitorUnitOfWork, new CpuStatusRepository(cpuMonitorUnitOfWork)); }
// 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()) { // dev excetion page 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(); } // redirect to https app.UseHttpsRedirection(); // use static files app.UseStaticFiles(); app.UseRouting(); // auths app.UseAuthentication(); app.UseAuthorization(); app.UseEndpoints(endpoints => { // admin area endpoints.MapAreaControllerRoute( "admin", "admin", "Admin/{controller=Home}/{action=Index}/{id?}"); // normal MVC endpoints.MapControllerRoute( "default", "{controller=Home}/{action=Index}/{id?}"); }); // initialize db AppDbInitializer.Initialize(app.ApplicationServices); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { // Dependency Injection InitializeContainer(app); // Logging loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); // MVC app.UseMvc(); app.UseDefaultFiles(); app.UseStaticFiles(); // Entity Framework AppDbInitializer.Initialize(app.ApplicationServices); // Mapping Infrastructure.AutoMapper.Register(); app.UseSwagger(); app.UseSwaggerUi(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ApplicationDbContext context)//, RoleManager<IdentityRole> roleManager,UserManager<User> userManager) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); //app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions //{ // HotModuleReplacement = true //}); } 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(); }); AppDbInitializer.Initialize(context); }