Thank you! It solves my problem
On Wed, Feb 5, 2014 at 1:03 PM, Marco Pivetta <[email protected]> wrote: > Hey there! > > > On 5 February 2014 10:58, Anton Serdyuk <[email protected]> wrote: > >> Hi, folks! >> >> There is some problem I can not solve. I have some code which I want to >> wire up with zend-di. There are many classes which have constructor >> parameter lets say UserRepository $userRepository. UserRepository is an >> interface, and there is DoctrineUserRepository. So I want somehow tell to >> di-container it should use DoctrineUserRepository instead UserRepository >> every time. For example I want sometimes call $di->get('UserRepository') >> or >> I can make it as constructor parameter to another class - it doesnt >> matter. >> > > > That's a fairly common use case: you will need to set a "preference" for > the DI container. Something like following: > > > 'instance' => array( > 'preference' => array( > 'Zend\EventManager\EventManagerInterface' => 'EventManager', > 'Zend\ServiceManager\ServiceLocatorInterface' => > 'ServiceManager', > ), > ), > > > > That will do the trick, and will tell the container to use "EventManager" > (or whatever concrete class name) whenever the interface for it is used. > > I think there's also some more about it on > http://ocramius.github.io/blog/zend-framework-2-controllers-and-dependency-injection-with-zend-di/ > > Cheers, > > Marco Pivetta > > http://twitter.com/Ocramius > > http://ocramius.github.com/ > >
