From a9eda803cfc87bdb44d7d809d2cee346111cedeb Mon Sep 17 00:00:00 2001 From: malik masis Date: Wed, 7 Dec 2022 16:22:12 +0300 Subject: [PATCH] Update DefaultHomePageMiddleware.cs --- .../DefaultHomePageMiddleware.cs | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/DefaultHomePageMiddleware.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/DefaultHomePageMiddleware.cs index bb30a5276c..297f765bbc 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/DefaultHomePageMiddleware.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/DefaultHomePageMiddleware.cs @@ -1,28 +1,24 @@ -using System.Threading.Tasks; +using System.Net; +using System.Threading.Tasks; using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.DependencyInjection; using Volo.CmsKit.Pages; using Volo.CmsKit.Public.Pages; namespace Volo.CmsKit.Public.Web; -public class DefaultHomePageMiddleware +public class DefaultHomePageMiddleware : IMiddleware, ITransientDependency { - private readonly RequestDelegate _next; - private readonly IPagePublicAppService _pagePublicAppService; - - public DefaultHomePageMiddleware(RequestDelegate next, IPagePublicAppService pagePublicAppService) - { - _next = next; - _pagePublicAppService = pagePublicAppService; - } - public async Task InvokeAsync(HttpContext httpContext) + public async Task InvokeAsync(HttpContext context, RequestDelegate next) { + var _pagePublicAppService = context.RequestServices.GetRequiredService(); var page = await _pagePublicAppService.FindDefaultHomePageAsync(); - if (page is not null && httpContext.Request.Path.Value == "/") + if (page is not null && context.Request.Path.Value == "/") { - httpContext.Request.Path = $"{PageConsts.UrlPrefix}{page.Slug}"; + context.Request.Path = $"{PageConsts.UrlPrefix}{page.Slug}"; } - - await _next(httpContext); + + await next(context); } } \ No newline at end of file