P
Peter Morris [Droopy eyes software]
I have an object persistence framework I have written, this framework
expects every object to descend ultimately from PersistentObject and to have
a constructor (ObjectSpace objectSpace) so that objects may be recreated.
PersistentObject's constructor will do something like this
this.ObjectSpace = objectSpace;
objectSpace.RegisterObjectCreation(this);
The object space will record a reference to this new object + do something
like this
if (!IsLoadingFromDatabase)
newInstance.AfterConstruction();
The virtual AfterConstruction 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 : PersistentObject
{
public CustomerAction(Customer customer)
: base(customer.ObjectSpace)
{
this.Customer = customer;
}
protected override void AfterConstruction()
{
//Do some stuff with this.Customer
}
}
My problem is that this.Customer has not been set by the time
AfterConstruction is called.
1) new CustomerAction(someCustomer);
2) CustomerAction constructor is called
3) Base constructor (customer.ObjectSpace is called)
4) CustomerAction.AfterConstruction 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!
expects every object to descend ultimately from PersistentObject and to have
a constructor (ObjectSpace objectSpace) so that objects may be recreated.
PersistentObject's constructor will do something like this
this.ObjectSpace = objectSpace;
objectSpace.RegisterObjectCreation(this);
The object space will record a reference to this new object + do something
like this
if (!IsLoadingFromDatabase)
newInstance.AfterConstruction();
The virtual AfterConstruction 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 : PersistentObject
{
public CustomerAction(Customer customer)
: base(customer.ObjectSpace)
{
this.Customer = customer;
}
protected override void AfterConstruction()
{
//Do some stuff with this.Customer
}
}
My problem is that this.Customer has not been set by the time
AfterConstruction is called.
1) new CustomerAction(someCustomer);
2) CustomerAction constructor is called
3) Base constructor (customer.ObjectSpace is called)
4) CustomerAction.AfterConstruction 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!