Created Entities by Aurelius

Hi Wagner,


My entities classes are all descendants from a base class, that I use as a way to initialize context values.

This is not Table Inheritance, just normal class inheritance.

My question is that since those objects can be created by Aurelius, I don´t know how to use dependency Injection and give to the created object my IContext interface to let it know the values to be used on the created context.

Let me explain, for example, if the user is working with company = 1, then anything that will be created, a new item, a new customer, will have the property company = 1 

On the old days :) we used this by accessing global variables, or singletons for that.

However, since I am using unit testing, and global variables are evil, I prefer to follow the DI patter.

Another problem is that when using web I can eventually many threads running, and I cannot depend on singletons for these kind of thing.

Is there anything on Aurelius that I could depend on when the object is constructed to reference it, specially new empty ones. 

I cannot rely on the TAureliusDataset only, since this is part of the view and is kept dumbest possible. I need to implement on my model layer and that deals with the non-component stuff.

I need to give to new created entities my IContext interface, and that needs to be on the same context of the manager, since there is this multi-threading, and I keep total separation between threads.

Appreciate any help....

Eduardo

ok,


I have found that there is plenty of options on the TAureliusDataSet and what I have asked on this thread is found here:

  TDatasetCreateObjectEvent = procedure(Dataset: TDataset; var NewObject: TObject) of object;

  //<snip>

  property OnCreateObject: TDatasetCreateObjectEvent;

It give me the change to create and initialize things.

Hovewer I would like to suggest that the same events could be used in a non-control way. It could be part of the overral structure without the need of the dataset, since it looks like more "old way".

Thank you