Add GenericFormDataValidator2 that doesn't take DataType in constructor #547
+203
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
GenericFormDataValidator<TModel>
is a (currently undocumented) convenience abstract class for implementingIFormDataValidator
. The benefit is thatHasRelevantChanges
andValidateFormData
has a signature ofTModel
instead ofobject
and the helper methodCreateValidationIssue
that takes an expression (aka linq) instead of providing the field the issue relates to as a string. In additionValidateFormData
does not return a list of issues, but instead you register them withAddValidationIssue
andCreateValidationIssue
.The previous version of this abstract class defined the
DataType
property and to ensure that users actually set this property, it was a required parameter in the constructor. Today I realised that it was hard to read and understand how that magic string ended up in thebase()
call, and that an abstract class can declare an abstract property so that inheriting classes is required to implement the property. I think this results in much prettier code.The new way is almost the same as when you implement the
IFormDataValidator
interface directly (needs theoverride
keyword because of the abstract class)Breaking change, alternatives?
This is a breaking change which will cause those apps that has started to use
GenericFormDataValidator<TModel>
. As it is not documented, I think that would be very few cases.Add obsolete message, to better explain the change
We can improve the error message by adding the following constructors.
Create a new abstract class
As this is just a utility class, we could potentially just add a new one with a new name and the slightly changed semantics. This will ensure that no direct changes will be needed until the old (obsolete) version is removed in v9. Good suggestions for names would be very welcome. See suggestion here
Related Issue(s)
Verification
Documentation