@@ -41,7 +41,7 @@ public async Task OnActionExecutionAsync(ActionExecutingContext actionExecutingC
41
41
if ( endpoint != null &&
42
42
( ( autoValidationMvcConfiguration . ValidationStrategy == ValidationStrategy . Annotations &&
43
43
! endpoint . Metadata . OfType < FluentValidationAutoValidationAttribute > ( ) . Any ( ) && ! endpoint . Metadata . OfType < AutoValidationAttribute > ( ) . Any ( ) ) ||
44
- endpoint . Metadata . OfType < AutoValidateNever > ( ) . Any ( ) ) )
44
+ endpoint . Metadata . OfType < AutoValidateNeverAttribute > ( ) . Any ( ) ) )
45
45
{
46
46
HandleUnvalidatedEntries ( actionExecutingContext ) ;
47
47
@@ -58,47 +58,46 @@ public async Task OnActionExecutionAsync(ActionExecutingContext actionExecutingC
58
58
var parameterType = parameter . ParameterType ;
59
59
var bindingSource = parameter . BindingInfo ? . BindingSource ;
60
60
61
- var hasAutoValidateAlwaysAttribute = parameterInfo ? . HasCustomAttribute < AutoValidateAlways > ( ) ?? false ;
62
- var hasAutoValidateNeverAttribute = parameterInfo ? . HasCustomAttribute < AutoValidateNever > ( ) ?? false ;
61
+ var hasAutoValidateAlwaysAttribute = parameterInfo ? . HasCustomAttribute < AutoValidateAlwaysAttribute > ( ) ?? false ;
62
+ var hasAutoValidateNeverAttribute = parameterInfo ? . HasCustomAttribute < AutoValidateNeverAttribute > ( ) ?? false ;
63
63
64
- if ( subject != null && parameterType . IsCustomType ( ) && ! hasAutoValidateNeverAttribute && ( hasAutoValidateAlwaysAttribute || HasValidBindingSource ( bindingSource ) ) )
64
+ if ( subject != null && parameterType . IsCustomType ( ) &&
65
+ ! hasAutoValidateNeverAttribute && ( hasAutoValidateAlwaysAttribute || HasValidBindingSource ( bindingSource ) ) &&
66
+ serviceProvider . GetValidator ( parameterType ) is IValidator validator )
65
67
{
66
- if ( serviceProvider . GetValidator ( parameterType ) is IValidator validator )
67
- {
68
- // ReSharper disable once SuspiciousTypeConversion.Global
69
- var validatorInterceptor = validator as IValidatorInterceptor ;
70
- var globalValidationInterceptor = serviceProvider . GetService < IGlobalValidationInterceptor > ( ) ;
68
+ // ReSharper disable once SuspiciousTypeConversion.Global
69
+ var validatorInterceptor = validator as IValidatorInterceptor ;
70
+ var globalValidationInterceptor = serviceProvider . GetService < IGlobalValidationInterceptor > ( ) ;
71
71
72
- IValidationContext validationContext = new ValidationContext < object > ( subject ) ;
72
+ IValidationContext validationContext = new ValidationContext < object > ( subject ) ;
73
73
74
- if ( validatorInterceptor != null )
75
- {
76
- validationContext = validatorInterceptor . BeforeValidation ( actionExecutingContext , validationContext ) ?? validationContext ;
77
- }
74
+ if ( validatorInterceptor != null )
75
+ {
76
+ validationContext = validatorInterceptor . BeforeValidation ( actionExecutingContext , validationContext ) ?? validationContext ;
77
+ }
78
78
79
- if ( globalValidationInterceptor != null )
80
- {
81
- validationContext = globalValidationInterceptor . BeforeValidation ( actionExecutingContext , validationContext ) ?? validationContext ;
82
- }
79
+ if ( globalValidationInterceptor != null )
80
+ {
81
+ validationContext = globalValidationInterceptor . BeforeValidation ( actionExecutingContext , validationContext ) ?? validationContext ;
82
+ }
83
83
84
- var validationResult = await validator . ValidateAsync ( validationContext , actionExecutingContext . HttpContext . RequestAborted ) ;
84
+ var validationResult = await validator . ValidateAsync ( validationContext , actionExecutingContext . HttpContext . RequestAborted ) ;
85
85
86
- if ( validatorInterceptor != null )
87
- {
88
- validationResult = validatorInterceptor . AfterValidation ( actionExecutingContext , validationContext ) ?? validationResult ;
89
- }
86
+ if ( validatorInterceptor != null )
87
+ {
88
+ validationResult = validatorInterceptor . AfterValidation ( actionExecutingContext , validationContext ) ?? validationResult ;
89
+ }
90
90
91
- if ( globalValidationInterceptor != null )
92
- {
93
- validationResult = globalValidationInterceptor . AfterValidation ( actionExecutingContext , validationContext ) ?? validationResult ;
94
- }
91
+ if ( globalValidationInterceptor != null )
92
+ {
93
+ validationResult = globalValidationInterceptor . AfterValidation ( actionExecutingContext , validationContext ) ?? validationResult ;
94
+ }
95
95
96
- if ( ! validationResult . IsValid )
96
+ if ( ! validationResult . IsValid )
97
+ {
98
+ foreach ( var error in validationResult . Errors )
97
99
{
98
- foreach ( var error in validationResult . Errors )
99
- {
100
- actionExecutingContext . ModelState . AddModelError ( error . PropertyName , error . ErrorMessage ) ;
101
- }
100
+ actionExecutingContext . ModelState . AddModelError ( error . PropertyName , error . ErrorMessage ) ;
102
101
}
103
102
}
104
103
}
0 commit comments