DEV Community

DeChamp
DeChamp

Posted on

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

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 background and it’s a given for other languages I’ve used. However, I’ve learned early on the “why, it’s js” approach, where “it’s not needed”. My team and I are in discussion on the topic. What is your thoughts on it?

if you're able to, please provide examples of how you solved that same issues as InversifyJS did.

Top comments (3)

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.