You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by "Blower, Andy" <An...@proquest.co.uk> on 2011/12/01 12:15:13 UTC

IoC multiple service instances

I have an usual situation that I'm not sure what the best way of implementing is with T5 IoC. It feels like I need a Factory, but how that would fit in with the service binding and injection I'm not sure. I'm hoping that I can get some suggestions from the list.



I have a service that currently has a couple of different implementations, and I'm creating a third implementation that will actually hold 2+ instances of one of these existing implementations and then dynamically switch between them as directed by another new service. In the prototype, this new service implementation specifically instantiates the existing implementations using the 'new' keyword. I want to decouple this and be able to select which of the two original implementations should be instantiated for these internal instances.



This would be simple if I only needed one internal instance, or one per thread as I could just use service names and have a singleton or perthread service. If I knew how many instances I need then I could use multiple service names.



The only idea I have is to use a factory, but this feels more like things before using IoC.



Any suggestions/ideas welcome, and I hope my explanation makes sense.



Thanks,



Andy.