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

twitter logo github logo ・1 min read

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.

twitter logo DISCUSS (4)
markdown guide

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 proposes) 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).


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.


I had never heard of InversifyJS, but took a look and it looks like it provides for TypeScript what Spring provides for Java.

There's a lot to discuss on this topic, but to me, the most important question you should be asking yourself is: What style of application design does your team find most intuitive? If you are used to working with Java/Spring, then using a DI package for TypeScript might make perfect sense. To the vast majority of the JS community, however, it would be overkill - but that's less of a concern if you have an already established team with a strong preference.

Ultimately, you get to choose how your application is designed, so you have to pick what is best based on the constraints and goals of your specific situation. Do you need a DI framework? No. Do you need TypeScript? No. Do we need any frameworks or libraries at all? No. We choose these tools because we believe it will make our lives easier. Whether it does or not, however, has a lot to do with your circumstances and how you use it.


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.

Classic DEV Post from Dec 29 '18

What's your 🎉New Year Resolutions🎉 ?

I know you all must be thinking, "Ugh... Not this again. These things never wor...

DeChamp profile image
Just a coder and a dad. I love my family and I love to code!!!! started coding at 11, so I have 25 years under my belt. Still love learning about it every day. Follow me on instagram @codeFiend