Inject 2 instances of same class in constructor

Posted 3 years ago by Woodlandtrek


Here is a situation I ran across recently: If I have 2 different instances of the same class bound into the IoC container, how can I select the correct one when using dependency injection?


$app(‘foo1’) = new Foo(‘hello’); 
$app(‘foo2’) = new Foo(‘world’); 

How would I inject $app(‘foo2’) into a constructor (assuming both instances have been registered into the container as singletons)?


Please sign in or create an account to participate in this conversation.