From c74ee641784a9ff06537218f198775357d34943a Mon Sep 17 00:00:00 2001 From: maliming Date: Mon, 28 Dec 2020 10:10:05 +0800 Subject: [PATCH] Add AbpActionContextExtensions. --- .../Mvc/AbpActionContextExtensions.cs | 20 +++++++++++++++ .../Mvc/Auditing/AbpAuditActionFilter.cs | 7 +++--- .../Mvc/Auditing/AbpAuditPageFilter.cs | 7 +++--- .../ExceptionHandling/AbpExceptionFilter.cs | 25 ++++++------------- .../AbpExceptionPageFilter.cs | 23 ++++++----------- .../Mvc/Features/AbpFeatureActionFilter.cs | 10 +++----- .../Mvc/Features/AbpFeaturePageFilter.cs | 6 ++--- .../GlobalFeatureActionFilter.cs | 6 +---- .../GlobalFeatures/GlobalFeaturePageFilter.cs | 6 +---- .../AspNetCore/Mvc/Uow/AbpUowActionFilter.cs | 5 ++-- .../AspNetCore/Mvc/Uow/AbpUowPageFilter.cs | 5 ++-- .../Validation/AbpValidationActionFilter.cs | 3 +-- 12 files changed, 53 insertions(+), 70 deletions(-) create mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpActionContextExtensions.cs diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpActionContextExtensions.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpActionContextExtensions.cs new file mode 100644 index 0000000000..07b54cc5df --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpActionContextExtensions.cs @@ -0,0 +1,20 @@ +using Microsoft.AspNetCore.Mvc.Filters; +using Microsoft.Extensions.DependencyInjection; + +namespace Volo.Abp.AspNetCore.Mvc +{ + internal static class AbpActionContextExtensions + { + public static T GetRequiredService(this FilterContext context) + where T : class + { + return context.HttpContext.RequestServices.GetRequiredService(); + } + + public static T GetService(this FilterContext context, T defaultValue = default) + where T : class + { + return context.HttpContext.RequestServices.GetService() ?? defaultValue; + } + } +} diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Auditing/AbpAuditActionFilter.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Auditing/AbpAuditActionFilter.cs index 2e05204304..33db273c07 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Auditing/AbpAuditActionFilter.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Auditing/AbpAuditActionFilter.cs @@ -3,7 +3,6 @@ using System.Diagnostics; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc.Abstractions; using Microsoft.AspNetCore.Mvc.Filters; -using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; using Volo.Abp.Aspects; using Volo.Abp.Auditing; @@ -53,7 +52,7 @@ namespace Volo.Abp.AspNetCore.Mvc.Auditing auditLog = null; auditLogAction = null; - var options = context.HttpContext.RequestServices.GetRequiredService>().Value; + var options = context.GetRequiredService>().Value; if (!options.IsEnabled) { return false; @@ -64,13 +63,13 @@ namespace Volo.Abp.AspNetCore.Mvc.Auditing return false; } - var auditLogScope = context.HttpContext.RequestServices.GetRequiredService().Current; + var auditLogScope = context.GetRequiredService().Current; if (auditLogScope == null) { return false; } - var auditingHelper = context.HttpContext.RequestServices.GetRequiredService(); + var auditingHelper = context.GetRequiredService(); if (!auditingHelper.ShouldSaveAudit(context.ActionDescriptor.GetMethodInfo(), true)) { return false; diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Auditing/AbpAuditPageFilter.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Auditing/AbpAuditPageFilter.cs index 70fac063b5..cc12120280 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Auditing/AbpAuditPageFilter.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Auditing/AbpAuditPageFilter.cs @@ -3,7 +3,6 @@ using System.Diagnostics; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc.Abstractions; using Microsoft.AspNetCore.Mvc.Filters; -using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; using Volo.Abp.Aspects; using Volo.Abp.Auditing; @@ -58,7 +57,7 @@ namespace Volo.Abp.AspNetCore.Mvc.Auditing auditLog = null; auditLogAction = null; - var options = context.HttpContext.RequestServices.GetRequiredService>().Value; + var options = context.GetRequiredService>().Value; if (!options.IsEnabled) { return false; @@ -69,13 +68,13 @@ namespace Volo.Abp.AspNetCore.Mvc.Auditing return false; } - var auditLogScope = context.HttpContext.RequestServices.GetRequiredService().Current; + var auditLogScope = context.GetRequiredService().Current; if (auditLogScope == null) { return false; } - var auditingHelper = context.HttpContext.RequestServices.GetRequiredService(); + var auditingHelper = context.GetRequiredService(); if (!auditingHelper.ShouldSaveAudit(context.HandlerMethod.MethodInfo, true)) { return false; diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ExceptionHandling/AbpExceptionFilter.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ExceptionHandling/AbpExceptionFilter.cs index 2a28d2cc0a..6c447bc893 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ExceptionHandling/AbpExceptionFilter.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ExceptionHandling/AbpExceptionFilter.cs @@ -1,11 +1,10 @@ -using System; +using System; using System.Text; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Abstractions; using Microsoft.AspNetCore.Mvc.Filters; -using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Options; @@ -57,14 +56,13 @@ namespace Volo.Abp.AspNetCore.Mvc.ExceptionHandling //TODO: Trigger an AbpExceptionHandled event or something like that. context.HttpContext.Response.Headers.Add(AbpHttpConsts.AbpErrorFormat, "true"); - context.HttpContext.Response.StatusCode = (int) context.HttpContext.RequestServices + context.HttpContext.Response.StatusCode = (int) context .GetRequiredService() .GetStatusCode(context.HttpContext, context.Exception); - var remoteServiceErrorInfo = context.HttpContext.RequestServices - .GetRequiredService().Convert(context.Exception, - context.HttpContext.RequestServices.GetRequiredService>() - .Value.SendExceptionsDetailsToClients); + var exceptionHandlingOptions = context.GetRequiredService>().Value; + var exceptionToErrorInfoConverter = context.GetRequiredService(); + var remoteServiceErrorInfo = exceptionToErrorInfoConverter.Convert(context.Exception, exceptionHandlingOptions.SendExceptionsDetailsToClients); context.Result = new ObjectResult(new RemoteServiceErrorResponse(remoteServiceErrorInfo)); @@ -72,22 +70,15 @@ namespace Volo.Abp.AspNetCore.Mvc.ExceptionHandling var remoteServiceErrorInfoBuilder = new StringBuilder(); remoteServiceErrorInfoBuilder.AppendLine($"---------- {nameof(RemoteServiceErrorInfo)} ----------"); - remoteServiceErrorInfoBuilder.AppendLine(context.HttpContext.RequestServices - .GetRequiredService().Serialize(remoteServiceErrorInfo, indented: true)); + remoteServiceErrorInfoBuilder.AppendLine(context.GetRequiredService().Serialize(remoteServiceErrorInfo, indented: true)); - var logger = context.HttpContext.RequestServices.GetService>() ?? - NullLogger.Instance; + var logger = context.GetService>(NullLogger.Instance); logger.LogWithLevel(logLevel, remoteServiceErrorInfoBuilder.ToString()); logger.LogException(context.Exception, logLevel); - await context.HttpContext - .RequestServices - .GetRequiredService() - .NotifyAsync( - new ExceptionNotificationContext(context.Exception) - ); + await context.GetRequiredService().NotifyAsync(new ExceptionNotificationContext(context.Exception)); context.Exception = null; //Handled! } diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ExceptionHandling/AbpExceptionPageFilter.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ExceptionHandling/AbpExceptionPageFilter.cs index a91980043b..f3666d2f91 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ExceptionHandling/AbpExceptionPageFilter.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ExceptionHandling/AbpExceptionPageFilter.cs @@ -5,7 +5,6 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Abstractions; using Microsoft.AspNetCore.Mvc.Filters; -using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Options; @@ -69,14 +68,13 @@ namespace Volo.Abp.AspNetCore.Mvc.ExceptionHandling //TODO: Trigger an AbpExceptionHandled event or something like that. context.HttpContext.Response.Headers.Add(AbpHttpConsts.AbpErrorFormat, "true"); - context.HttpContext.Response.StatusCode = (int) context.HttpContext.RequestServices + context.HttpContext.Response.StatusCode = (int) context .GetRequiredService() .GetStatusCode(context.HttpContext, context.Exception); - var remoteServiceErrorInfo = context.HttpContext.RequestServices - .GetRequiredService().Convert(context.Exception, - context.HttpContext.RequestServices.GetRequiredService>() - .Value.SendExceptionsDetailsToClients); + var exceptionHandlingOptions = context.GetRequiredService>().Value; + var exceptionToErrorInfoConverter = context.GetRequiredService(); + var remoteServiceErrorInfo = exceptionToErrorInfoConverter.Convert(context.Exception, exceptionHandlingOptions.SendExceptionsDetailsToClients); context.Result = new ObjectResult(new RemoteServiceErrorResponse(remoteServiceErrorInfo)); @@ -84,21 +82,14 @@ namespace Volo.Abp.AspNetCore.Mvc.ExceptionHandling var remoteServiceErrorInfoBuilder = new StringBuilder(); remoteServiceErrorInfoBuilder.AppendLine($"---------- {nameof(RemoteServiceErrorInfo)} ----------"); - remoteServiceErrorInfoBuilder.AppendLine(context.HttpContext.RequestServices - .GetRequiredService().Serialize(remoteServiceErrorInfo, indented: true)); + remoteServiceErrorInfoBuilder.AppendLine(context.GetRequiredService().Serialize(remoteServiceErrorInfo, indented: true)); - var logger = context.HttpContext.RequestServices.GetService>() ?? - NullLogger.Instance; + var logger = context.GetService>(NullLogger.Instance); logger.LogWithLevel(logLevel, remoteServiceErrorInfoBuilder.ToString()); logger.LogException(context.Exception, logLevel); - await context.HttpContext - .RequestServices - .GetRequiredService() - .NotifyAsync( - new ExceptionNotificationContext(context.Exception) - ); + await context.GetRequiredService().NotifyAsync(new ExceptionNotificationContext(context.Exception)); context.Exception = null; //Handled! } diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Features/AbpFeatureActionFilter.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Features/AbpFeatureActionFilter.cs index 82cc65ff0b..2d468b30d9 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Features/AbpFeatureActionFilter.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Features/AbpFeatureActionFilter.cs @@ -1,7 +1,6 @@ using Microsoft.AspNetCore.Mvc.Filters; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc.Abstractions; -using Microsoft.Extensions.DependencyInjection; using Volo.Abp.Aspects; using Volo.Abp.DependencyInjection; using Volo.Abp.Features; @@ -10,9 +9,7 @@ namespace Volo.Abp.AspNetCore.Mvc.Features { public class AbpFeatureActionFilter : IAsyncActionFilter, ITransientDependency { - public async Task OnActionExecutionAsync( - ActionExecutingContext context, - ActionExecutionDelegate next) + public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) { if (!context.ActionDescriptor.IsControllerAction()) { @@ -24,9 +21,8 @@ namespace Volo.Abp.AspNetCore.Mvc.Features using (AbpCrossCuttingConcerns.Applying(context.Controller, AbpCrossCuttingConcerns.FeatureChecking)) { - await context.HttpContext.RequestServices.GetRequiredService().CheckAsync( - new MethodInvocationFeatureCheckerContext(methodInfo) - ); + var methodInvocationFeatureCheckerService = context.GetRequiredService(); + await methodInvocationFeatureCheckerService.CheckAsync(new MethodInvocationFeatureCheckerContext(methodInfo)); await next(); } diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Features/AbpFeaturePageFilter.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Features/AbpFeaturePageFilter.cs index 3f54597c2a..913716ab33 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Features/AbpFeaturePageFilter.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Features/AbpFeaturePageFilter.cs @@ -1,7 +1,6 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc.Abstractions; using Microsoft.AspNetCore.Mvc.Filters; -using Microsoft.Extensions.DependencyInjection; using Volo.Abp.Aspects; using Volo.Abp.DependencyInjection; using Volo.Abp.Features; @@ -27,9 +26,8 @@ namespace Volo.Abp.AspNetCore.Mvc.Features using (AbpCrossCuttingConcerns.Applying(context.HandlerInstance, AbpCrossCuttingConcerns.FeatureChecking)) { - await context.HttpContext.RequestServices.GetRequiredService().CheckAsync( - new MethodInvocationFeatureCheckerContext(methodInfo) - ); + var methodInvocationFeatureCheckerService = context.GetRequiredService(); + await methodInvocationFeatureCheckerService.CheckAsync(new MethodInvocationFeatureCheckerContext(methodInfo)); await next(); } diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/GlobalFeatures/GlobalFeatureActionFilter.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/GlobalFeatures/GlobalFeatureActionFilter.cs index f0f08fad16..9498b31a3f 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/GlobalFeatures/GlobalFeatureActionFilter.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/GlobalFeatures/GlobalFeatureActionFilter.cs @@ -3,7 +3,6 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Abstractions; using Microsoft.AspNetCore.Mvc.Filters; -using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using Volo.Abp.DependencyInjection; @@ -24,10 +23,7 @@ namespace Volo.Abp.AspNetCore.Mvc.GlobalFeatures if (!IsGlobalFeatureEnabled(context.Controller.GetType(), out var attribute)) { - var logger = - context.HttpContext.RequestServices.GetRequiredService>() ?? - NullLogger.Instance; - + var logger = context.GetService>(NullLogger.Instance); logger.LogWarning($"The '{context.Controller.GetType().FullName}' controller needs to enable '{attribute.Name}' feature."); context.Result = new NotFoundResult(); return; diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/GlobalFeatures/GlobalFeaturePageFilter.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/GlobalFeatures/GlobalFeaturePageFilter.cs index 18c56ab698..a3415f6be8 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/GlobalFeatures/GlobalFeaturePageFilter.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/GlobalFeatures/GlobalFeaturePageFilter.cs @@ -3,7 +3,6 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Abstractions; using Microsoft.AspNetCore.Mvc.Filters; -using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using Volo.Abp.DependencyInjection; @@ -29,10 +28,7 @@ namespace Volo.Abp.AspNetCore.Mvc.GlobalFeatures if (!IsGlobalFeatureEnabled(context.HandlerInstance.GetType(), out var attribute)) { - var logger = - context.HttpContext.RequestServices.GetRequiredService>() ?? - NullLogger.Instance; - + var logger = context.GetService>(NullLogger.Instance); logger.LogWarning($"The '{context.HandlerInstance.GetType().FullName}' page needs to enable '{attribute.Name}' feature."); context.Result = new NotFoundResult(); return; diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Uow/AbpUowActionFilter.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Uow/AbpUowActionFilter.cs index 8f11ede0a5..d4b2087281 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Uow/AbpUowActionFilter.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Uow/AbpUowActionFilter.cs @@ -3,7 +3,6 @@ using System.Net.Http; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc.Abstractions; using Microsoft.AspNetCore.Mvc.Filters; -using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; using Volo.Abp.AspNetCore.Uow; using Volo.Abp.DependencyInjection; @@ -37,7 +36,7 @@ namespace Volo.Abp.AspNetCore.Mvc.Uow var options = CreateOptions(context, unitOfWorkAttr); - var unitOfWorkManager = context.HttpContext.RequestServices.GetRequiredService(); + var unitOfWorkManager = context.GetRequiredService(); //Trying to begin a reserved UOW by AbpUnitOfWorkMiddleware if (unitOfWorkManager.TryBeginReserved(AbpUnitOfWorkMiddleware.UnitOfWorkReservationName, options)) @@ -70,7 +69,7 @@ namespace Volo.Abp.AspNetCore.Mvc.Uow if (unitOfWorkAttribute?.IsTransactional == null) { - var abpUnitOfWorkDefaultOptions = context.HttpContext.RequestServices.GetRequiredService>().Value; + var abpUnitOfWorkDefaultOptions = context.GetRequiredService>().Value; options.IsTransactional = abpUnitOfWorkDefaultOptions.CalculateIsTransactional( autoValue: !string.Equals(context.HttpContext.Request.Method, HttpMethod.Get.Method, StringComparison.OrdinalIgnoreCase) ); diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Uow/AbpUowPageFilter.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Uow/AbpUowPageFilter.cs index 7dbc65319e..6ab5ba8909 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Uow/AbpUowPageFilter.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Uow/AbpUowPageFilter.cs @@ -3,7 +3,6 @@ using System.Net.Http; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc.Abstractions; using Microsoft.AspNetCore.Mvc.Filters; -using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; using Volo.Abp.AspNetCore.Uow; using Volo.Abp.DependencyInjection; @@ -42,7 +41,7 @@ namespace Volo.Abp.AspNetCore.Mvc.Uow var options = CreateOptions(context, unitOfWorkAttr); - var unitOfWorkManager = context.HttpContext.RequestServices.GetRequiredService(); + var unitOfWorkManager = context.GetRequiredService(); //Trying to begin a reserved UOW by AbpUnitOfWorkMiddleware if (unitOfWorkManager.TryBeginReserved(AbpUnitOfWorkMiddleware.UnitOfWorkReservationName, options)) @@ -75,7 +74,7 @@ namespace Volo.Abp.AspNetCore.Mvc.Uow if (unitOfWorkAttribute?.IsTransactional == null) { - var abpUnitOfWorkDefaultOptions = context.HttpContext.RequestServices.GetRequiredService>().Value; + var abpUnitOfWorkDefaultOptions = context.GetRequiredService>().Value; options.IsTransactional = abpUnitOfWorkDefaultOptions.CalculateIsTransactional( autoValue: !string.Equals(context.HttpContext.Request.Method, HttpMethod.Get.Method, StringComparison.OrdinalIgnoreCase) ); diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Validation/AbpValidationActionFilter.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Validation/AbpValidationActionFilter.cs index fe74419654..751afe84d0 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Validation/AbpValidationActionFilter.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Validation/AbpValidationActionFilter.cs @@ -1,7 +1,6 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc.Abstractions; using Microsoft.AspNetCore.Mvc.Filters; -using Microsoft.Extensions.DependencyInjection; using Volo.Abp.DependencyInjection; namespace Volo.Abp.AspNetCore.Mvc.Validation @@ -19,7 +18,7 @@ namespace Volo.Abp.AspNetCore.Mvc.Validation return; } - context.HttpContext.RequestServices.GetRequiredService().Validate(context.ModelState); + context.GetRequiredService().Validate(context.ModelState); await next(); } }