r/softwarearchitecture • u/goetas • Jun 18 '25
Article/Video Why JavaScript Deserves Dependency Injection
I've always valued Dependency Injection (DI) - not just for testing, but for writing clean, modular, and maintainable code. Some of the most expected advantages of DI is the improved developer experience.
Yet in the JavaScript world, I kept hearing excuses like "DI is too complex" or "We don't need it, our code is simple." But when "simple" turns into thousands of tangled lines, global patches, and copy-pasted wiring... is that still simple? Most of the JS projects I have seen or were toy-projects or were giant-monsters.
I wrote a post why DI matters in the JavaScript world, especially on the server side, where the old frontend constraints no longer apply.
Yes, you can use Jest and all the most convoluted patching strategies... but with DI none of that is needed.
If you're building anything beyond a toy app, this is worth your time.
Here is the link to the post https://www.goetas.com/blog/why-javascript-deserves-dependency-injection/
A common excuse in JavaScript i hear is that JS tends to be used as a functional programming language; In that context DI looks different when compared to traditional object-oriented languages, in the next post I will talk about DI in functional programming (using partial function application).
View all comments
Show parent comment
-1
u/goetas Jun 18 '25
>The article jumps directly from not using DI to using a DI framework without arguing wether the added complexity, abstraction and third party dependency is worth it or necessary. Ad opposed to just using plain DI.
I wrote a whole blog post on why a dependency injection framework is worth the effort. Here is the link: https://www.goetas.com/blog/dependency-injection-why-it-matters-not-only-for-testing/
(it was also linked in the post above as well)
>yes one should absolutely test this with a filesystem, which includes missing or malformed files!
i'm not sure this makes sense at all. a malformed file or a malformed string are the same .