How to avoid injecting dependencies into an object so that it can pass them on?
Posted
by Pheter
on Stack Overflow
See other posts from Stack Overflow
or by Pheter
Published on 2010-04-07T10:36:52Z
Indexed on
2010/04/07
10:43 UTC
Read the original article
Hit count: 351
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.
© Stack Overflow or respective owner