I have parent root(Mater) object as BusinessBase which has BusinessListBase(ChildList) object as a child.
Parent (BusinessBase)
- Child List (BusinessListBase)
- Child (BusinessBase)
I have a custom business rule implemented in child object (BusinessBase of ChildList), which depends on parent root(Mater) property. Now when parent root(Mater) property is changed, how to notify child object?
There is override method OnChildChanged which fires when any child property changed. Is there any way to fires custom rules on child object and show property status when parent property has been changed?
You can override PropertyHasChanged in parent object and rerun rules for child objects when that specific property has changed.
PropertyHasChanged will only be called when property content has changed.
Thanks JonnyBee for prompt reply
I have override PropertyHasChanged in parent object. But how can I check business rules for each child in ChildList?
I have tried below two methods for check business rules.
BusinessRules.CheckRules() and BusinessRules.CheckObjectRules(). But it does not fire business rules for child objects and does not update property status.
So can you please guide me how to rerun business rules for each child in Child List so than custom business rules execute and property status is updated?
you can extend the child object with a "CheckAllRules" that notify UI of changes like this:
public void CheckAllRules()
{
var propertyNames = BusinessRules.CheckRules();
if (ApplicationContext.PropertyChangedMode == ApplicationContext.PropertyChangedModes.Windows)
OnPropertyChanged(property);
else
foreach (var name in propertyNames)
OnPropertyChanged(name);
}
And call this in from the PropertyHasChanged in the root object.
I have tried your sugestion and Its worsk. Thanks a lot....
Shah,
I have an interface IGrandChildList that all lists implement to expose the Parent and override the SetParent method of the child object. I thenadd a handler OnParentChanged that will allow me to execute my rules.
Protected Overrides Sub SetParent(parent As Csla.Core.IParent)
AddHandler DirectCast(parent, IGrandChildList).GetParent.PropertyChanged, AddressOf OnParentChanged
MyBase.SetParent(parent)
End Sub
Protected Overridable Sub OnParentChanged(sender As Object, e As System.ComponentModel.PropertyChangedEventArgs)
' Check Rules here
End Sub
Copyright (c) Marimer LLC