File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55global using HotChocolate . Resolvers ;
66global using FluentValidation ;
77global using FluentValidation . Results ;
8+ using System . Linq ;
89using System . Runtime . CompilerServices ;
910using FluentValidation . Internal ;
1011using Microsoft . Extensions . DependencyInjection ;
@@ -216,7 +217,14 @@ public static GetValidationContext<TInput> ValidationContextWithStrategy<TInput>
216217 IValidationContext validationContext ,
217218 Type validatorType )
218219 {
219- var validators = ( IValidator [ ] ) inputValidatorContext . MiddlewareContext . Services . GetServices ( validatorType ) ;
220+ // The default DI container returns IValidator[] as the actual underlying type
221+ // However, this is not the case for some custom DI containers, so we add a fallback to cast the array manually
222+ var validatorsEnumerable = inputValidatorContext . MiddlewareContext . Services . GetServices ( validatorType ) ;
223+
224+ var validators = validatorsEnumerable as IValidator [ ]
225+ ?? validatorsEnumerable
226+ . OfType < IValidator > ( )
227+ . ToArray ( ) ;
220228
221229 if ( validators is { Length : 0 } )
222230 {
You can’t perform that action at this time.
0 commit comments