From a1c1f1c523917512e9599126fdd93d20f8ee7d3d Mon Sep 17 00:00:00 2001 From: Sullivan008 Date: Wed, 24 Jun 2020 15:06:13 +0200 Subject: [PATCH] Remove ApplicationDeploy Extension Middleware and Inject this Context in Configure Method and Migrate it. --- .../Core/Middlewares/ApplicationDeploy.cs | 31 ------------------- .../Middlewares/ApplicationDeployExtension.cs | 12 ------- SimpleCRUDExample/Startup.cs | 8 ++--- 3 files changed, 3 insertions(+), 48 deletions(-) delete mode 100644 SimpleCRUDExample/Core/Middlewares/ApplicationDeploy.cs delete mode 100644 SimpleCRUDExample/Core/Middlewares/ApplicationDeployExtension.cs diff --git a/SimpleCRUDExample/Core/Middlewares/ApplicationDeploy.cs b/SimpleCRUDExample/Core/Middlewares/ApplicationDeploy.cs deleted file mode 100644 index bdba87b..0000000 --- a/SimpleCRUDExample/Core/Middlewares/ApplicationDeploy.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System.Threading.Tasks; -using Data.DataAccessLayer.Context; -using Microsoft.AspNetCore.Http; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.DependencyInjection; - -namespace SimpleCRUDExample.Core.Middlewares -{ - public class ApplicationDeploy - { - private readonly RequestDelegate _next; - - public ApplicationDeploy(RequestDelegate next) - { - _next = next; - } - - public async Task Invoke(HttpContext httpContext) - { - using (IServiceScope serviceScope = httpContext.RequestServices.GetRequiredService().CreateScope()) - { - using (CRUDAppContext appContext = serviceScope.ServiceProvider.GetService()) - { - appContext.Database.Migrate(); - } - } - - await _next(httpContext); - } - } -} diff --git a/SimpleCRUDExample/Core/Middlewares/ApplicationDeployExtension.cs b/SimpleCRUDExample/Core/Middlewares/ApplicationDeployExtension.cs deleted file mode 100644 index ef3407b..0000000 --- a/SimpleCRUDExample/Core/Middlewares/ApplicationDeployExtension.cs +++ /dev/null @@ -1,12 +0,0 @@ -using Microsoft.AspNetCore.Builder; - -namespace SimpleCRUDExample.Core.Middlewares -{ - public static class ApplicationDeployExtension - { - public static IApplicationBuilder UseApplicationDeploy(this IApplicationBuilder builder) - { - return builder.UseMiddleware(); - } - } -} \ No newline at end of file diff --git a/SimpleCRUDExample/Startup.cs b/SimpleCRUDExample/Startup.cs index 1dda1af..87ce4eb 100644 --- a/SimpleCRUDExample/Startup.cs +++ b/SimpleCRUDExample/Startup.cs @@ -8,7 +8,6 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using SimpleCRUDExample.Core.Configurations; -using SimpleCRUDExample.Core.Middlewares; using SimpleCRUDExample.Core.Models.ConfigModels; namespace SimpleCRUDExample @@ -38,7 +37,7 @@ public void ConfigureServices(IServiceCollection services) services.ConfigureAuthService(); services.ConfigureCookieService(); services.Configure(_configuration.GetSection("DevLoginConfig")); - + services.ConfigureBusinessEngines(); services.ConfigureCoreModules(); @@ -47,7 +46,7 @@ public void ConfigureServices(IServiceCollection services) services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); } - public void Configure(IApplicationBuilder app, IHostingEnvironment env) + public void Configure(IApplicationBuilder app, IHostingEnvironment env, CRUDAppContext context) { if (env.IsDevelopment()) { @@ -62,9 +61,8 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env) app.UseCookiePolicy(); app.UseAuthentication(); - - app.UseApplicationDeploy(); + context.Database.Migrate(); app.UseMvc(routes => {