Closed lmsantin closed 8 years ago
BusinessRules are always executed on a per-property basis.
So the execution order is "property", "priority ascending".(Edited - changed to priority - was sortorder)
And it is perfectly legal to have priority less than 0 (to be executed before the default value of 0).
@jonnybee just to know if I got you. "sortorder" means priority
Yes, it does.
@jonnybee We are using CSLA 4.5.700.0
We are suppresssing the rule execution using the ICheckRules Technique.
What must expect about the rule priorities when we invoke the CheckRules method?
You will get a BusinessRules.CheckRules to check all rules in the object.:
void ICheckRules.CheckRules()
{
BusinessRules.CheckRules();
}
And check rules in turn does a CheckObjectRules and then a foreach property a CheckRules(property)
public List<string> CheckRules()
{
if (_suppressRuleChecking)
return new List<string>();
RunningRules = true;
var affectedProperties = CheckObjectRules(RuleContextModes.CheckRules, false);
var properties = TypeRules.Rules.Where(p => p.PrimaryProperty != null)
.Select(p => p.PrimaryProperty)
.Distinct();
foreach (var property in properties)
affectedProperties.AddRange(CheckRules(property, RuleContextModes.CheckRules));
RunningRules = false;
if (!RunningRules && !RunningAsyncRules)
_target.AllRulesComplete();
return affectedProperties.Distinct().ToList();
}
CheckObjectRules will execute rules where PrimaryProperty == null ordered by RulePriority ASC ChgeckRules is called per-property and will execute rules ordered by RulePriority ASC (in the first pass) and the rerun rules for affected properties.
See: https://jonnybekkum.wordpress.com/2012/04/29/unit-test-csla-4-businessrules/ and https://jonnybekkum.wordpress.com/2011/08/29/csla-4-2-rules-update/ and https://jonnybekkum.wordpress.com/2012/11/07/csla-4-5-ruleengine-update/
Thank a lot @jonnybee
I have modified the priority of some business rules in my class and I thought they will execute from priority 0 to higher.
What I got when I tested was all the rules executing in the order they are defined inside the protected override void AddBusinessRules() method.
Is that ok?