Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Advanced controller configuration #11

Closed
naprstek opened this issue Dec 1, 2016 · 2 comments
Closed

Advanced controller configuration #11

naprstek opened this issue Dec 1, 2016 · 2 comments

Comments

@naprstek
Copy link

naprstek commented Dec 1, 2016

Whatever application uses logging and very often caching or other services (doctrine?). How to pass this services to every controller and not add thousands parameters to the constructors? Similar way like default session manager in chapter 15.3.2.

@olegkrivtsov
Copy link
Owner

olegkrivtsov commented Dec 1, 2016

Good question.

How to pass this services to every controller and not add thousands parameters to the constructors?

In ZF2, there was ServiceLocator pattern allowing to get dependencies from service manager in any part of your app (in controllers, services, etc.) In ZF3, you have to pass dependencies explicitly (this means you have to pass every dependency to every controller). It is not too difficult, and it removes "hidden" dependencies and makes your code easier to understand. If you don't want to pass dependencies manually, use Zend\Mvc\Controller\LazyControllerAbstractFactory which can save you some efforts.

Similar way like default session manager in chapter 15.3.2.

Default session manager is a legacy feature from ZF1. Actually, I created an issue zendframework/zend-session#58 in Zend\Session component where I asked them to remove the default "static" session manager at all. Default session manager creates implicit "hidden" dependencies in your code. Fortunatelly or unfortunatelly, they do not answer to my request.

@olegkrivtsov
Copy link
Owner

I've extended the Website Operation and Model-View-Controller chapters to better describe factories (and particularly the LazyControllerAbstractFactory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants