3 ms·
Why would you need dependency injection if you can dynamically replace imported modules through Node's module system?
by tthisk 7y ago
Why would you need dependency injection if you can dynamically replace imported modules through Node's module system?
- kostarelo 7y agoAre 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.