public static async Task Main(string[] args) { var host = CreateWebHostBuilder(args).Build(); // inserting seeding logic here based on // https://stackoverflow.com/questions/46222692/asp-net-core-2-seed-database using (var scope = host.Services.CreateScope()) { var context = scope.ServiceProvider .GetRequiredService <HolidayContext>(); await DbInitialiser.Seed(context); } host.Run(); }
public static void Main(string[] args) { //BuildWebHost(args).Run(); var host = BuildWebHost(args); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var context = services.GetRequiredService <AppDbContext>(); DbInitialiser.Seed(context); } catch (Exception) { } } host.Run(); }
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 context = services.GetRequiredService <CrmDbContext>(); DbInitialiser.Seed(context); } catch (Exception) { //we could log this in a real-world situation } } 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(); app.UseStaticFiles(new StaticFileOptions { FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), @"node_modules")), RequestPath = new PathString("/vendor") }); } app.UseStatusCodePages(); app.UseStaticFiles(); app.UseSession(); app.UseMvcWithDefaultRoute(); DbInitialiser.Seed(app); }