Spring4D - How to get the same instance of Logger for a class group?
Spring4D - How to get the same instance of Logger for a class group?
Everything works on interfaces, but I skip interfaces for simplicity.
I have a base class:
TBaseClass = class
fLogger : TLogger;
constructor (aLogger : TLogger);
end;
Two usable classes are inherited from it:
TClassA = class(TBaseClass)
fWorkClass1 : TWorkClassA;
fWorkClass2 : TWorkClassB;
end;
TClassB = class(TBaseClass)
fWorkClass3 : TWorkClassC;
fWorkClass4 : TWorkClassD;
end;
...which have working classes:
TWorkClassA = class
fLogger : TLogger;
constructor (aLogger : TLogger);
end;
TWorkClassB = class
fLogger : Tlogger;
constructor (aLogger : TLogger);
end;
TWorkClassC = class
fLogger : TLogger;
constructor (aLogger : TLogger);
end;
TWorkClassD = class
fLogger : Tlogger;
constructor (aLogger : TLogger);
end;
These objects I use directly in the code:
var
ObjectA : TClassA;
ObjectB : TClassB;
ObjectA and ObjectB create their own separate workgroups, and I would like all objects in the group to use the same fLogger instance.
I would like to create two instances of TLogger:
- first for objects: ObjectA, fWorkClass1, fWorkClass2
- second for object: ObjectB, fWorkClass3, fWorkClass4
How to get in Spring4D?
Everything works on interfaces, but I skip interfaces for simplicity.
I have a base class:
TBaseClass = class
fLogger : TLogger;
constructor (aLogger : TLogger);
end;
Two usable classes are inherited from it:
TClassA = class(TBaseClass)
fWorkClass1 : TWorkClassA;
fWorkClass2 : TWorkClassB;
end;
TClassB = class(TBaseClass)
fWorkClass3 : TWorkClassC;
fWorkClass4 : TWorkClassD;
end;
...which have working classes:
TWorkClassA = class
fLogger : TLogger;
constructor (aLogger : TLogger);
end;
TWorkClassB = class
fLogger : Tlogger;
constructor (aLogger : TLogger);
end;
TWorkClassC = class
fLogger : TLogger;
constructor (aLogger : TLogger);
end;
TWorkClassD = class
fLogger : Tlogger;
constructor (aLogger : TLogger);
end;
These objects I use directly in the code:
var
ObjectA : TClassA;
ObjectB : TClassB;
ObjectA and ObjectB create their own separate workgroups, and I would like all objects in the group to use the same fLogger instance.
I would like to create two instances of TLogger:
- first for objects: ObjectA, fWorkClass1, fWorkClass2
- second for object: ObjectB, fWorkClass3, fWorkClass4
How to get in Spring4D?
Jeroen Wiert Pluimers No, see this too groups.google.com - [IoC and DI] Specific instances for object groups
ReplyDeleteJacek Laskowski did a manually written resolver help?
ReplyDelete(I am saving quite a few of your questions in my blog so I can find them back in the future when G+ has died)
Jeroen Wiert Pluimers I pass the TLogger instance from top to bottom (by all classes) through the constructor - but the object at the beginning creates a Resolver. In such a situation both groups of classes receive different instance of TLogger.
ReplyDeleteHappy New Year! :-)