Best way to Trigger Validation on Entire Object Graph?

Best way to Trigger Validation on Entire Object Graph?

Old forum URL:

mosgath posted on Tuesday, March 22, 2011

In our object design we have Header - > Lines -> Line -> Material.  When data changes on Header, the Line and Material need to have validation rules reran to recalculate pricing options and validate other items validated on selections from the header.  The BusinessRules.CheckRules() is only validate the current object's rules, not the children or grandchildren, etc.   What is the best way to trigger the rules in child based on data in the parent? 

We are using CSLA 4.1 with a Silverlight client and have rules that are both Asynchronous and Synchronous at all levels.

ajj3085 replied on Tuesday, March 22, 2011

Create internal instance methods on your child classes, which the parent class can call.  For collections, these should loop through the collection calling this same method on the items in the collection.  The method can just call check rules on itself.

mosgath replied on Monday, March 28, 2011

Thanks Andy.  That is what I figured, but wanted to make sure there wasn't a better way.  Since our object model consists of many children on the parent, I separated it a little and created the separate CheckRules by child and a master function that I could check the current object rules and the children rules.  Then in the Child objects, I included similar functions for their children.  We also had the requirement that one of the properties needed to recheck all children rules while another only needed to check one of the children. I then created Business Rules to call the appropriate function.

internal void CheckRules(Boolean checkSelf)
            if (checkSelf)
            { this.BusinessRules.CheckRules(); }


        internal void CheckChild1Rules()
            if (this.Child1 != null)

        internal void CheckChild2Rules()
            if (this.Child2 != null)

        internal void CheckChild3Rules()
            if (this.Child3 != null)

Copyright (c) Marimer LLC