I am adding a "rounding" business rule to round a decimal property value to the number of decimal places specified in a separate integer property. This works nicely if both properties are members of the business object in question. As in the following VB.Net code...
BusinessRules.AddRule(New Round(_decimalProperty, _precisionProperty))
I have a private Round class that inherits from CommonBusinessRule and its constructor is as follows:
Public Sub New(decimalProperty As IPropertyInfo, precisionProperty As IPropertyInfo)
MyBase.New(decimalProperty)
InputProperties = New List(Of IPropertyInfo)()
InputProperites.Add(decimalProperty)
InputProperties.Add(precisionProperty)
End Sub
This triggers the rule Execute whenever either property changes, and the Execute code rounds just exactly like I want.
The Problem: I now have a situation where the precisionProperty is a property of the Parent business object. When the CSLA method for adding Business Rules for the Child Business Object is called, the Parent member of the Child Business Object is null, so I can't get to a reference of the parent's property. Is there any point in time AFTER the Parent field is no longer null, that I am allowed to add a new Business Rule? If so in what method? Is there another approach?
We have looked into passing down a reference to the parent business object (via constructors) to the child, but have decided against this approach for now (the child is actually 6 levels deep, and it appears this would require rework of our code generation schemes).