private void _DoAutomaticDbMigration(IApplicationBuilder app) { using (var sScope = app.ApplicationServices.GetService <IServiceScopeFactory>().CreateScope()) { PaymentAppContext context = sScope.ServiceProvider.GetRequiredService <PaymentAppContext>(); context.Database.Migrate(); } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, PaymentAppContext context) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseSwagger(); app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "Payment v1")); } app.UseRouting(); app.UseAuthorization(); context.Database.Migrate(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); }