DEV Community

Discussion on: Explain Dependency Injection (DI) like I am five.

Collapse
 
brandinchiu profile image
Brandin Chiu

Depending on your school of thought, some people may not find the way you interact with your classes to be terribly intuitive, as you need to have a good understanding of the underlying management.

Also, depending on which framework you're using, it may be easier or more difficult to handle how the framework manages constructor arguments for the classes you need.

On the bright side though it makes unit tests simpler because it's very easy to stib/mock your services since you're never interacting with them directly.

Thread Thread
 
tam360 profile image
Mirza

I guess the main challenge of using DI is having a solid knowledge of interface/class's internal workings. Since DI does all the things behind the curtain, it becomes annoying when one starts using them without understanding. This I think is true in the case of debugging.

Thread Thread
 
brandinchiu profile image
Brandin Chiu

For sure.

I personally think the pros outweigh the cons, but to each their own.