I have an interface called IService
and derived services like IServiceA : IService
, IServiceB : IService
, IServiceC : IService
, etc.
The implementation classes of those services needs a context parameter of type MyContext
, and some services will need a refernece to other services in that context. for example:
ServiceA : IServiceA
needs MyContext
and IServiceC
(in constructor).
ServiceB : IServiceB only needs MyContext
.
I want to create an abstract factory that will create every service
upon request. something like:T GetService<T>(/*MyContext context - ?*/) where T : IService;
but i don't quite know how to add the context part. I understand that the MyContext parameter is part of the implementation details of every service, so I'll be happy to hear
about different ways to solve this problem.- I also need a way to create those services according to their context
value, so that for example multiple requests to create
IServiceA
with the sameMyContext
parameter will return the same instance of IServiceA and if a request forIServiceA
with differentMyContext
parameter will return a different instance. - Finally, I need a way to integrate it with a DI Container (Castle Windsor preferred) so that the creation and the context handling will occur close to the application root.
Thanks