The validation framework in DotVMM is not extensible. We can't plug-in custom validation frameworks, client-side validators, error messages, etc. We should change validators to make that possible:
IPropertyValidator
abstraction for ValidationAttribute, etc.
.IsValid() returns whether property value is valid
IPropertyValidationRule
replaces ViewModelPropertyValidationRule
.Name can be used to localize error messages
.ClientRuleName identifies client-side validator to use
we will also need to make our scripts extensible
.Validator is an implementation of IPropertyValidator
.GetClientParameters() returns parameters for the client-side validator
.GetErrorMessage() returns error message
it should return localized error message when possible
we can either use IStringLocalizer or our own IErrorMessageLocalizer
IValidationMetadataProvider
replaces IViewModelValidationMetadataProvider and IValidationRuleTranslator
should be registered in DotVVM configuration (collection ValidationMetadataProviders)
.GetRulesForProperty() returns implementations of IPropertyValidationRule
ViewModelValidator
collects rules from metadata providers and validates a view model
we should handle IValidatableObject somewhere else
default implementation for DataAnnotations
sample for FluentValidation
Similar design should solve most of our issues with validation extensibility. But I am still not sure how to handle localization. Client-side rules are currently cached somewhere in DefaultViewModelSerializer so we can't change error messages at runtime. @exyi what do you think?
The validation framework in DotVMM is not extensible. We can't plug-in custom validation frameworks, client-side validators, error messages, etc. We should change validators to make that possible:
IPropertyValidator
ValidationAttribute
, etc..IsValid()
returns whether property value is validIPropertyValidationRule
ViewModelPropertyValidationRule
.Name
can be used to localize error messages.ClientRuleName
identifies client-side validator to use.Validator
is an implementation ofIPropertyValidator
.GetClientParameters()
returns parameters for the client-side validator.GetErrorMessage()
returns error messageIStringLocalizer
or our ownIErrorMessageLocalizer
IValidationMetadataProvider
IViewModelValidationMetadataProvider
andIValidationRuleTranslator
ValidationMetadataProviders
).GetRulesForProperty()
returns implementations ofIPropertyValidationRule
ViewModelValidator
IValidatableObject
somewhere elseSimilar design should solve most of our issues with validation extensibility. But I am still not sure how to handle localization. Client-side rules are currently cached somewhere in
DefaultViewModelSerializer
so we can't change error messages at runtime. @exyi what do you think?Do you have something to add?