-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Validation via data annotations does not support dependency injection / resolution #157
Comments
reddogaw
pushed a commit
to reddogaw/Cocona
that referenced
this issue
Sep 2, 2024
-- Resolves mayuki#157 (mayuki#157) -- Places IServiceProvider into the `CoconaParameterValidationContext` -- Uses ValidationContext overload that supports providing the IoC container (https://learn.microsoft.com/en-us/dotnet/api/system.componentmodel.dataannotations.validationcontext.-ctor?view=net-8.0#system-componentmodel-dataannotations-validationcontext-ctor(system-object-system-iserviceprovider-system-collections-generic-idictionary((system-object-system-object)))
reddogaw
pushed a commit
to reddogaw/Cocona
that referenced
this issue
Sep 2, 2024
-- Resolves mayuki#157 (mayuki#157) -- Places IServiceProvider into the `CoconaParameterValidationContext` -- Uses ValidationContext overload that supports providing the IoC container (https://learn.microsoft.com/en-us/dotnet/api/system.componentmodel.dataannotations.validationcontext.-ctor?view=net-8.0#system-componentmodel-dataannotations-validationcontext-ctor(system-object-system-iserviceprovider-system-collections-generic-idictionary((system-object-system-object)))
reddogaw
added a commit
to reddogaw/Cocona
that referenced
this issue
Sep 2, 2024
-- Resolves mayuki#157 (mayuki#157) -- Places IServiceProvider into the `CoconaParameterValidationContext` -- Uses ValidationContext overload that supports providing the IoC container (https://learn.microsoft.com/en-us/dotnet/api/system.componentmodel.dataannotations.validationcontext.-ctor?view=net-8.0#system-componentmodel-dataannotations-validationcontext-ctor(system-object-system-iserviceprovider-system-collections-generic-idictionary((system-object-system-object)))
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In a custom data annotation, the
ValidationContext
typically supports acting as anIServiceProvider
to resolve dependencies required for the validation action.This support is typically provided by the ValidationContext constructor overload which allows you to pass the IServiceProvider used by the application. However, that's currently not being passed by Cocona, so it's leading to unregistered dependency exceptions when resolving within a custom validation attribute's
IsValid
method.Example which is silly but indicative:
The text was updated successfully, but these errors were encountered: