-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Make full property path more accessible #2132
Comments
As I mentioned in the other issue that you linked to, the display name is intended to be user-readable, which is why it doesn't contain the full property path. The full property path is made available to you as a property on each
No, it is not super easy to add it here. The full property path is only constructed when validation occurs, as it relies on information about the object being validated (eg indexers etc) - it's dynamic. The display name resolver must support standalone execution, outside of a validation run. This is needed in order to provide metadata for UI libraries (for example, ASP.NET's clientside validation), where it's necessary to obtain the failure message without invoking the validator. This is why the DisplayName resolver only has access to information from when the validator is constructed (type, member & expression), but not runtime contextual information.
This is doable. We can add a
FluentValidation encourages explicitness over automatic/magic changes to default behaviour. An explicit call for every rule is recommended, as it's then very clear you're overriding the default behaviour with something nonstandard. If you think this "stinks" then you're welcome to use a different library. |
Is your feature request related to a problem? Please describe.
We need to use the full property path for the display name globally. I know that you can create an extension method
WithFullName()
like this guy did #1906 (comment). Doing that, however, would require me to addWithFullName()
after EVERY RULE in every validator which stinks.For example:
ValidatorOptions.Global.DisplayNameResolver
would have been the perfect place to fix my problem, but it does not provide the property path. It would be super easy to add it there, but that would be a breaking change.Describe the solution you'd like
Describe alternatives you've considered
I came up with solution, but it is ugly. I'm hoping I can throw this monstrosity away and that there is a simple solution that I was unaware of. Note: I am a FluentValidation newbie. I am sure this is not what the ValidatorSelectors are for, but it was the only place I could find to hook in. To use it, you just call this:
Here is my workaround:
Additional Context
No response
The text was updated successfully, but these errors were encountered: