appany / AppAny.HotChocolate.FluentValidation

Input field HotChocolate GraphQL + FluentValidation integration
MIT License
71 stars 16 forks source link

ValidationDefaults Validators() assumes the underlying type returned from a DI container resulting in an exception for a custom DI container #111

Closed WORMrus closed 2 months ago

WORMrus commented 3 months ago

The problematic line: https://github.com/appany/AppAny.HotChocolate.FluentValidation/blob/770b7ad4f5e7d6238b8a5fe2f99d5ff77a86665d/src/ValidationDefaults.cs#L219

The call to GetServices() returns an IEnumerable<object?>, It would not be correct to assume that the underlying type is an array (object[]). While the default DI container indeed returns an array, this may not hold in all cases.

Real-life example: I was looking into Wolverine for messaging, which requires you to use Lamar. Lamar returns a List<T> instead of an array which results in a runtime InvalidCastException.

sergeyshaykhullin commented 3 months ago

@WORMrus Could you please provide a pr for this fix?

WORMrus commented 2 months ago

@sergeyshaykhullin Sorry, took me some time to notice a notification. Sure, I will. Seems like an easy enough fix.

WORMrus commented 2 months ago

@sergeyshaykhullin please see https://github.com/appany/AppAny.HotChocolate.FluentValidation/pull/112

sergeyshaykhullin commented 2 months ago

@WORMrus https://www.nuget.org/packages/AppAny.HotChocolate.FluentValidation/0.11.2