// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, DataSeed seed, StoreContext context, ILoggerFactory loggerFactory) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseCors("CorsPolicy"); seed.Seed(context, loggerFactory); app.UseHttpsRedirection(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "api/{controller}/{action}/{id?}" ); }); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, DataSeed seed) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseCors("CorsPolicy"); } 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(); } seed.SeedData(20, 1000); app.UseHttpsRedirection(); app.UseMvc(routes => routes.MapRoute("default", "api/{controller}/{action}/{id?}")); }
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 userManager = services.GetRequiredService <UserManager <AppUser> >(); context.Database.Migrate(); DataSeed.SeedDataAsync(context, userManager).Wait(); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occured during migration"); } } host.Run(); }