After attending ZendCon 2012 I saw how a lot of classes in ZF2 that
implemented DI and had their dependencies passed to them through the
constructor. I understand that ZF2 has a Service Manager that helps
with this. I'm trying to learn how to implement this and learn its
best practices.

And then... I loaded up the ZfcUser module and saw that the User
Service 
(https://github.com/ZF-Commons/ZfcUser/blob/master/src/ZfcUser/Service/User.php)
was not quite following this pattern, in fact it was hiding it's
dependencies behind a bunch of lazy loading getters. Now, this module
was initially written by Evan Coury so I think it's safe to say that
this module is well written or at least follows the suggested zf2 best
practices.

My question is, why is this class hiding its dependencies behind
getters and actually getting them from the Service Manager instead of
defining them explicitly in the constructor?

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!

Thanks!
Julian

-- 
List: [email protected]
Info: http://framework.zend.com/archives
Unsubscribe: [email protected]


Reply via email to