Depends on your needs. Di is good for automated instantiation if that's your use case. For injections that won't change over time, you can simply use the ServiceManager.
Marco Pivetta http://twitter.com/Ocramius http://ocramius.github.com/ On 21 March 2013 03:05, mbneto <[email protected]> wrote: > In that case, should I still try to use the DI or go with the > ServiceManager? > > > On Tue, Mar 19, 2013 at 12:03 AM, Marco Pivetta <[email protected]>wrote: > >> That's actually possible by using a `@Di\Inject` annotation (or something >> like that). Annotation support is quite limited right now though. >> >> Marco Pivetta >> >> http://twitter.com/Ocramius >> >> http://ocramius.github.com/ >> >> >> On 19 March 2013 03:31, mbneto <[email protected]> wrote: >> >>> Hi Marco, >>> >>> Thank you. I was, indeed, reading an outdated version of the >>> documentation the one found at ( >>> http://framework.zend.com/manual/2.1/en/modules/zend.di.introduction.html) >>> plus your links cleared the questions I had. >>> >>> I can know make it work by setting the desired concrete implementation. >>> :) >>> >>> The question now is what path should I take to store and use these >>> definitions. >>> >>> Seems that storing in as arrays will give me the necessary performance >>> that production apps need. So should I forget about this >>> $di->instanceManager()->addTypePreference() >>> and go straight to the array definition? >>> >>> I tend to like the idea (since I am a Doctrine2 user as well) to have >>> annotation and somehow generate those arrays from them since I have the >>> definitions closer to the actual source code. Is it possible to do so with >>> Zend\Di? >>> >>> Regards. >>> >>> >>> >>> On Sun, Mar 17, 2013 at 11:37 PM, Marco Pivetta <[email protected]>wrote: >>> >>>> Heya! >>>> >>>> Sorry for cross-posting, but I replied this some time ago at >>>> http://stackoverflow.com/questions/15136925/missing-examples-for-zend-framework-2-tutorial-learning-dependency-injection >>>> >>>> The answer above is valid when using Zend\Di, of course. >>>> >>>> You can use the `preference` setting to pick a specific `BarInterface` >>>> implementation when one is requestede: >>>> >>>> >>>> http://stackoverflow.com/questions/12426744/servicelocatorawareinterface-confuses-the-di-container-when-running-module-tests >>>> >>>> >>>> Marco Pivetta >>>> >>>> http://twitter.com/Ocramius >>>> >>>> http://ocramius.github.com/ >>>> >>>> >>>> On 16 March 2013 22:18, mbneto <[email protected]> wrote: >>>> >>>>> Hi, >>>>> >>>>> I found just one documentation about the Zend DIC but I could not find >>>>> how >>>>> to inform which concrete class should it create based on an interface >>>>> >>>>> Ex. >>>>> >>>>> class Foo >>>>> { >>>>> public function __construct(BarInterface $bar) >>>>> { >>>>> } >>>>> } >>>>> >>>>> class Bar implements BarInterface >>>>> { >>>>> public function __construct($someArg) >>>>> { >>>>> } >>>>> } >>>>> >>>>> I want to create a new instance of Foo using the DIC. How can I set >>>>> this? >>>>> >>>>> $foo = $dic->get('Foo', ?) >>>>> >>>>> Thanks, >>>>> >>>> >>>> >>> >> >
