How to avoid injecting dependencies into an object so that it can pass them on?
- by Pheter
I am interested in applying dependency injection to my current project, which makes use of the MVC pattern.
My controllers will call the models and therefore will need to inject the dependencies into the models. To do this, the controller must have the dependencies (such as a database object) in the first place. The controller doesn't need to make use of some of these dependencies (such as the database object), so I feel that it shouldn't be given this dependency. However, it has to have these dependencies if it is to inject them into the model objects.
How can I avoid having dependencies injected into an object just so that it can pass them on? Doing so feels wrong and can result in many dependencies being injected into an object.
Edit: I am using PHP.