PropertyProxyValidator support for multiple rulesets

Topics: Validation Application Block
Jan 16, 2009 at 1:31 PM
When validating using code, you can do this:

ValidationResults results = Validation.Validate(myCustomer, "RuleSetA", "RuleSetB");

I think the PropertyProxyValidator control should also support the ability to process multiple rulesets, not just one.  Either by passing a comma separated list of ruleset names or by making the property a string collection.

What would be the easiest way to get it to support multiple rulesets now?

I was planning to have 2 rulesets, a BaseApplicationRuleset and a ClientRuleset.  Both would likely always be applied, but 2 sets provide clean separation of rules from one deployment(client) to another, allowing customization of the ClientRuleset.

BaseApplicationRuleset would contain base rules, like stringlengthvalidator set for the database max column width, for instance.
ClientRuleset could be more restrictive, perhaps further limiting that same column to a shorter string.

Jan 17, 2009 at 4:12 AM
Why not just go for having 2 PropertyProxyValidators?  That's the easiest way I can think of, modifyng the source code would definitely be harder.

Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.
Jan 17, 2009 at 2:04 PM
Yeah, I did that in my prototype.  With a little more testing I've come to realize another wrinkle with multiple rulesets, being used in an overlapping fashion like I suggested.

Multiple rulesets means multiple validation errors for the same field, which would be confusing.  I was first thinking multiple rulesets might work almost like inheritance, but of course that is not the case.

So, a BaseApplicationRuleset that defines the StringLengthValidator for FirstName to be 100 (the max length in the database) and a second StringLengthValidator for FirstName for the ClientRuleSet that defines the length to be 50.

If the user enters a value that is > 100 and we are using both rulesets, they of course see 2 error messages:

First Name must be less than 100.
FirstName must be less than 50.

This is obviously less than ideal.

I think I am going to have to rework my idea to always use a single ruleset at any one time.