Can you short circuit CSLA's MinValue rule?

Can you short circuit CSLA's MinValue rule?

Old forum URL: forums.lhotka.net/forums/t/5817.aspx


xxxJasonxxx posted on Monday, November 17, 2008

I'm using CSLA 3.0.4.0 and I'm trying to short ciruit some validation rules.

I figured out how to short circuit the common "StringRequired" rule by changing it from this.....

ValidationRules.AddRule(AddressOf Csla.Validation.CommonRules.StringRequired, New Csla.Validation.RuleArgs("DateOrderTaken", "Date order taken"), 0)

.....to this....

ValidationRules.AddRule(AddressOf Csla.Validation.CommonRules.StringRequired, New Csla.Validation.RuleArgs("DateOrderTaken", "Date order taken", Csla.Validation.RuleSeverity.Error, True), 0)

But I cannot figure out how to short circuit the common "MinValue" rule for this rule.....

ValidationRules.AddRule(AddressOf Csla.Validation.CommonRules.MinValue(Of Integer), New Csla.Validation.CommonRules.MinValueRuleArgs(Of Integer)("OrderTypeId", "Order type number", -1), 0)

I expected the "MinValue" rule would be short circuited similar to the "StringRequired" rule.  But from what I'm seeing with the intellisense that does not appear to be the case.  I know I could write my own custom rule method and get it done that way, but that seems silly.  I have to be missing something here -- probably something obvious and simple.  Can anyone help?

xxxJasonxxx replied on Wednesday, November 19, 2008

bump Stick out tongue [:P]

RockfordLhotka replied on Wednesday, November 19, 2008

What are you trying to accomplish?

Short-circuiting works in two ways: automatic and manual.

Automatic works by priority. By default all priority 0 rules run, and if any fail then priority 1+ don't run. Similarly, if 0 and 1 pass, then 2 runs, but if any 2 fails then 3+ don't run. Etc.

Manual works by having the rule method itself indicate that no further rules should run. This is only really useful when used with priorities though, as rules within a priority will run in an indeterminate order.

But to get automatic short-circuiting, you don't need to do anything special beyond putting expensive rules at priority 1+ so they only run if all the cheap priority 0 rules pass.

xxxJasonxxx replied on Wednesday, November 19, 2008

Your descriptions made me realize that I misunderstood how short circuiting works.

Setting the priority number (automatic) will accomplish my goal.

Thanks Rocky.

Copyright (c) Marimer LLC