public static void Main(string[] args) { IConfig config = new Config(new ConfigData(new Logger(Uptime.ProcessId, LogLevel.Info))); IWebHost host = WebHost.CreateDefaultBuilder(args) .UseUrls("http://*:" + config.Port) .UseKestrel(options => { options.AddServerHeader = false; }) .UseIISIntegration() .UseHealthChecks("/health", TimeSpan.FromSeconds(1)) .UseStartup <Startup>() .Build(); using (IServiceScope scope = host.Services.CreateScope()) { IServiceProvider services = scope.ServiceProvider; try { TodoContext context = services.GetRequiredService <TodoContext>(); TodoInitializer.Initialize(context); } catch (Exception) { ILogger logger = services.GetRequiredService <ILogger>(); logger.Error("An error occured while seeding the database.", () => { }); } } host.Run(); }
public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseCookiePolicy(); app.UseMvcWithDefaultRoute(); // Ensure that the database and schema exists TodoInitializer.Initialize(app.ApplicationServices); }
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); app.UseEndpoints((endpoints) => endpoints.MapDefaultControllerRoute()); // Ensure that the database and schema exists TodoInitializer.Initialize(app.ApplicationServices); }