DEV Community

Whats your thoughts on using a DI Package for IOC within a node project?

DeChamp on July 15, 2019

I need some opinions on using DI package such as InversifyJS, with in your node projects (typescript). I’m torn on this. I come from a OOP backgrou...
Collapse
 
mfaghfoory profile image
Meysam Faghfouri • Edited

In my opinion, the least benefit that we'll have by using a DI is that we can test our upstream layers and services with fake dependencies as Angular does (for example you can inject an in-memory http interceptor and provide some fake data for testing purposes) without doing a lot of boring changes. another one is that you can change your application's behavior by changing dependencies in just one place without changing those in every place (Open-Closed principle).

Collapse
 
dechamp profile image
DeChamp

With jest, we are able to mock the modules and do the same effect. We finally went without DI module as we found we could do it using vanilla js.

Collapse
 
dechamp profile image
DeChamp

you know what, you make a good point. Is this making our lives easier? Well sure in some cases it could. Others maybe not. K.i.s.s. (keep it simple, stupid). Thanks for you feed back.