FluentValidation: Request: Add ObjectInstance to ValidationFailure

The Microsoft Blazor front-end uses an ObjectInstance/PropertyName combination to identify errors, whereas FluentValidation uses a RootObject/PathToProperty.

Could we have some way of retrieving the actual object + property name (rather than path)?

For example. A ValidationFailure for Person.HomeAddress.City would give us object Person.HomeAddress, string "City"

Take a look here for more information in a blog by Steve Sanderson - https://chrissainty.com/using-fluentvalidation-for-forms-validation-in-razor-components/

I’d be happy to submit a PR if you are open to the idea of this improvement and would like to discuss an approach you are happy with?

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 4
  • Comments: 18 (7 by maintainers)

Most upvoted comments

  • Update PropertyValidator to pass the parent rule instance to the ValidationFailure
  • Need to decide how to handle Custom validators where the user can create the ValidationFailure instance directly.
  • Ensure there are tests in place to make sure serialization isn’t affected