我可以对所有依赖项使用依赖注入吗? [重复]

All my PHP is Object Orinted and I want to use dependency injection for all dependencies ( i.e. classes that need other classes to work ). Is this O.K?

I think I posted to much information to be readable...but if you want specifics there are here.

Also, if this does not over-complicate the problem, can I use the Factory Pattern for all dependency injection? - Specifics are in the link above.

</div>

Well, yes.

The whole point of dependency injection is abstraction, give the function/method/object/class what it needs, and have it work it out inside of it. A factory for generating objects and variables to pass for DI is fine.

For instance:

public function pdo_select(PDO $pdo_connection, $table, $where_condition)

Here, we pass in everything we need, the connection object, the table name and the WHERE MySQL clause. We can further abstract this function by doing:

public function pdo_query(PDO $pdo_connection, $query)

Now, we aren't restricting our function to just selecting, we can do all sorts of queries.

But you see that you definitely can pass objects to different functions to work with.

Passing objects also gives you the nice touch of having type hinting, which would throw an error if a different kind of parameter is entered, helping you to debug.