Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Depencency injection question

I have a question regarding dependency injection pattern. My question is... If I go for constructor injection, injecting the dependencies for my class, what I get is a "big" constructor with many params. What if ie. I dont use some of the params in some methods? Ie. I have a service that exposes many methods. And a constructor with 10 parameters (all dependencies). But not all the methods uses all the dependencies. Some method will use only one dependency, another will use 3 dependencies. But DI container will resolve them all even if non are used.

To me this is a performance penalty of using DI container. Is this true?

like image 851
Luka Avatar asked Nov 03 '10 08:11

Luka


1 Answers

It seems your class is doing to much, that it does not comply to the S in SOLID (Single responsibility principle) , maybe you could split the class in multiple smaller classes with less dependencies. The fact that not all dependencies are used by all methods suggests this.

like image 198
Ruben Avatar answered Sep 28 '22 06:09

Ruben