Hacker News new | ask | show | jobs
by tthisk 2522 days ago
Why would you need dependency injection if you can dynamically replace imported modules through Node's module system?
1 comments

Are you referring to the `cache` property of the the module system? I personally consider this to be similar to monkey patch and way out of the reason of what was built for. It also restricts you in ways like having to set that up before calling the module that you want to test which for testing may lead to bloated test files.

With DI, you are treating any dependency the same way. Modules both external and yours codebase, environment variables and process information, etc.