// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (this.EnableCORS) { app.UseCors("FromAppSettings"); } if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseHsts(); } app.UseDefaultFiles(); app.UseStaticFiles(); app.UseAuthentication(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller}/{action=Index}/{id?}"); }); using (var scope = app.ApplicationServices.CreateScope()) { var db = scope.ServiceProvider.GetService <ExchangeDbContext>(); if (db.Database.IsInMemory()) { db.Database.EnsureCreated(); SeedSampleData.SeedDatabase(db); } else { db.Database.Migrate(); } } }
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 <AppIdentityDbContext>(); SeedSampleData.Seed(context).Wait();//<---Do your seeding here } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred while seeding the database."); } } host.Run(); }
public IActionResult SeedSampleData() { SeedSampleData data = new SeedSampleData(); return(Json(new { result = "Data loaded." })); }