Dear all,
I'm using CSLA 4.5.10. I'm facing trouble with some trivial rules computation:
SubTotal1 = Property1 * Property2
SubTotal2 = Property3 * Property4
Total = SubTotal1 + SubTotal2
I'm adding to my business object the following rules (the first parameter is the primary property, the 1st and 2nd parameters are input properties, the third parameter is an affected property):
ProdRule(Property1, Property2, SubTotal1),
ProdRule(Property3, Property3, SubTotal2),
SumRule(SubTotal1, SubTotal2, SubTotal)
I did understand that (if not overidden) rule only cascade 1 level. Thus that the above scenario was supported.
However, concretely this only works if 'SubTotal1' (the primary property) is affected.
This does not work when 'SubTotal2' is affected (ie. when either Property3 or Property4 were updated).
I was surprised to see that only PrimaryProperty is taken into account (instead of all InputProperties), to define which rules should run, cf. businessrules.cs ln 568:
var rules = from r in TypeRules.Rules
where ReferenceEquals(r.PrimaryProperty, property) //I was not expecting that
&& CanRunRule(r, executionContext)
orderby r.Priority
select r;
Am I wrongly assuming that CSLA engine should be designed to have my 'Total' computed (ie. the rule run) if either 'SubTotal1' or 'SubTotal2' are modified.
Thanks for your light,
Regards,
Gilles
Note: I would have expected to see something like,
var rules = from r in TypeRules.Rules
where ((ReferenceEquals(r.PrimaryProperty, property)
|| (r.InputProperties != null && r.InputProperties.Contains(property))) //I was expecting that instead
&& CanRunRule(r, executionContext)
orderby r.Priority
select r;