BusinessObject
BusinessObject Introduction
When you first create a BusinessObject it will naturally be the ‘master’, aka the one that creates the transaction. But in time it should be able to be consumed by another parent business object. In order to support this, we have to ensure that we have a transaction in our business object at the moment of creation, either by getting it from a parent object, or one gets created if none was provided. The moment where the object knows whether it got a transaction from the parent context is the Init method (explained below).
BusinessObject Lifecycle
Constructor call
Context passing (this is where the transaction gets passed from the parent businessobject if it gets created through CreateChildBusinessObject)
Init function call
BusinessObject Initialization
Never create BusinessObjects using new!!!
do NOT create child businessobjects in the constructor of the BusinessObject, as it does not (yet) have the transaction information available
use BusinessObjectFactory.CreateBusinessObject<T>(Transaction transaction) if you have a Transaction instance but you are not in the context of a BusinessObject (e.g. if you create a BusinessObject in a response window which got the Transaction from the main module). It's the main method. The transaction must be explicitly passed (can be null).
use myBusObj.CreateChildBusinessObject<T>(bool addToChildCollection), if you are within a Business Object and want to create a sub-BusinessObject
we call CreateChildBusinessObject(addToChildCollection: true) in busObj.Init(), when the child BusObj must remain permanently a child of the initial busObj
we call CreateChildBusinessObject(addToChildCollection: false) when the child BusObj has a local lifecycle
Init function implementation example:
Last updated