I have an object persistence framework I have written, this framework
expects every object to descend ultimately from PersistentObjec t and to have
a constructor (ObjectSpace objectSpace) so that objects may be recreated.
PersistentObjec t's constructor will do something like this
this.ObjectSpac e = objectSpace;
objectSpace.Reg isterObjectCrea tion(this);
The object space will record a reference to this new object + do something
like this
if (!IsLoadingFrom Database)
newInstance.Aft erConstruction( );
The virtual AfterConstructi on method on a class is therefore only ever
called when an object is initially created and not when it is recreated due
to being fetched from the database. This gives a good opportunity to create
composite objects etc. Here is my problem
public class CustomerAction : PersistentObjec t
{
public CustomerAction( Customer customer)
: base(customer.O bjectSpace)
{
this.Customer = customer;
}
protected override void AfterConstructi on()
{
//Do some stuff with this.Customer
}
}
My problem is that this.Customer has not been set by the time
AfterConstructi on is called.
1) new CustomerAction( someCustomer);
2) CustomerAction constructor is called
3) Base constructor (customer.Objec tSpace is called)
4) CustomerAction. AfterConstructi on is called
5) CustomerAction constructor code is executed
Why oh why wont dotnet let me execute some of my own code before calling the
base constructor? I can do this in methods.
I find it so restrictive!