Hi, I have a problem with new rule engine 4.5 of CSLA.
While returning object (not value!) from asynchronus validation rule with using RuleContext.AddOutValue, property is not being set if value from rule and the one that is currently present on property are equal (Object.Equals).
I was wondering do you have any advice on how to force setting of property despite the comparison that is made in Equals method.
Well, that is basically how LoadProperty/SetProperty works - to update the field only when the value differs.
I would take new look at the code and try to avoid this.
BusinessRules should NOT be used for data access and load new child objects (if I understand correctly).
I would rather prefer to do Async LazyLoad on the <bo>.<Property>
The only "safe" workaround is in the callback method to call LoadProperty(context.Target, PropertyInfo, null) so the values will differ when the rule engine processes the OutputValues.
Yes, it would be great if I can choose to "force" Load/SetProperty.
ProvideTargetWhenAsync/LoadProperty(context.Target, PropertyInfo, null) workaround is allowed when BusinessRule is async?
Yes, they are.
But remember - BusinessRules should NOT be used as Data Access to load business objects.
I am only using BusinessRule to fetch/replace readonly child object (key/value implementation of foreign key concept), for example, UI code can set only "key" part of foreign key property. Business rule then kick in, it fetch and replace that foreign key child object with key AND value (value can be string or read only "info" object) from database.
That way I'm keeping BO properties clean, can reuse rules and I can unit test business rules.
I hope I'm doing the right thing?
My preference is to have the key and value as separate properties in the BO.
ReadOnly objects may work with this - but editable must NEVER be used like this.
In terms of Undo and Serialization/Deserialization this is the best solution (IMO).
So I prefer to only use the key and then the async business rule will update the value in the BO.
Unit test and reuse of rules works just as good.
Copyright (c) Marimer LLC