Hey devs,

one problem drives me nuts, since I started working with ZF2 (never worked
with Version 1):

I'm in need of the service manager all the time. E.g. to access my config
in config/autoload/local.php via $sm->get('Config'). I need the service
manager everywhere. Controllers, models, you name it. And I don’t want to
pass it around by hand, which would make everything ugly.

Now I’ve started to implement ServiceLocatorAwareInterface in most classes.
But this has the two downsides for me:

1. The classes which make use of my ServiceLocatorAware classes need to
have acces to the service locater, as well, in order to instantiate the
objects. So even more ServiceLocatorAware classes and even more invokables
to be added to module.config.php.

2. The service manager is a property of all ServiceLocatorAware classes,
which can be difficult if you want to persist a ServiceLocatorAware model
e.g. to the session.

Now I'm starting to get the feeling the I haven’t really understood ZF2 and
the service manager. Injecting everything cannot be the solution, can it?
Should I really inject e.g. my global config into all classes? And if you
don’t want to have plain entity models but business models with some
process logic in them, you cannot abstain from the service manager either.

I would really appreciate any clarification on this topic. And I get the
impression a lot of others do, too.

Regards
Rob

Reply via email to