Im trying to see if there is a way to using FluentValidation without explicitly creating a validation model for every object type in my application.
Is this technically and currently possible?
Updated
To rephrase this, is it possible for FluentValidation to validate Rules WITHOUT a IValidator context? Instead, i would like to pass in the item instance to be validated and use validation Rules which are constructed on-the-fly.
Resolved
I was able to resolve by doing a kind of a hack solution. Here are basic details of what i did:
1) I created a class (GenericModel) which has a collection of objects representing properties in a model. 2) I created a validator class that inherits from AbstractValidator. 3) Based on GenericModel's collection of "property objects" + additional metadata about each property's validation rules and error messages, i was able to add FluentValues Rules, all at run-time. 4). At the EditForm i handled the OnSubmit event. In that event handler i execute validation via FluentValidation's ValidateAsync() method. 5). Finally, i iterate thru the validation results and update each field with appropriate CSS, error messages, highlighting...etc.
I was able to resolve by doing a kind of a hack solution. Here are basic details of what i did:
I created a class (GenericModel) which has a collection of objects representing properties in a model.
I created a validator class that inherits from AbstractValidator.
Based on GenericModel's collection of "property objects" + additional metadata about each property's validation rules and error messages, i was able to add FluentValues Rules, all at run-time.
At the EditForm i handled the OnSubmit event. In that event handler i execute validation via FluentValidation's ValidateAsync() method.
Finally, i iterate thru the validation results and update each field with appropriate CSS, error messages, highlighting...etc.