On Tue, Nov 13, 2012 at 8:50 PM, Julian Vidal <[email protected]>wrote:
> Isn't this in fact going against the DI principle of making
> dependencies explicit? Note that I might have misunderstood this
> completely so I'm trying to grasp the gist of it!
>
It's not against it.
It's still an "Inversion of Control" way of doing things, which is a good
thing.
ZF2 DI has been in active development in late 2011 and has gained a lot of
traction among contributors. At some point though, the performance and
config files' complexity became an issue. That's why ServiceManager idea
has been brought up.
Up until beta1 (AFAIR) nearly everything was defined in DI and config files
were humongous. Applications were slow, memory usage was through the roof,
the complexity actually rose as compared to ZF1 Application_Service or
similar. There were ideas on how to further optimise DI, but a group of
contributors came up with another idea: SM.
ServiceManager allows for more explicit way of building up services. For
example, instead of an array of arrays with 20 keys (which is required for
DI to be able to handle dependencies correctly and construct objects), you
can just use a _single_ factory function/class with a few "new This", "new
That" and "return $service" at the end.
There's no strict policy or recommendation against SM nor DI. Both are OK,
both have strengths and weaknesses. It's your choice which you'll use. Both
are recognised by Zend\Mvc and will be read from you app config.
As for modules - each module's author decides on which method to use. Again
- both are valid ways of handling dependencies and automatically
constructing instances. Evan chose SM factories in this example.
A.
--
__
/.)\ +48 695 600 936
\(./ [email protected]