Using Dependency Injection frameworks for classes with many dependencies

Well, while you can do this as described in other answers I believe there is more important thing to be answered regarding your example and that is that you are probably violating SRP principle with class having many dependencies.

What I would consider in your example is breaking up the class in couple of more coherent classes with focused concerns and thus the number of their dependencies would fall down.

Nikola’s law of SRP and DI

“Any class having more than 3
dependencies should be questioned for
SRP violation”

(To avoid lengthy answer, I posted in detail my answers on IoC and SRP blog post)

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)