In many cases in C# i can use interface to get loose coupling between components.
for example a component could retrieve an
ITextFileReader reader = dic.Resolve<ITextFileReader();
No matter which implementation is currently bound. For example in test environment i could pass a spy or mock.
In node.js i use
require('./myTextReader.js")
but there is a fix dependency to that specific file. what is the best practice to get the described behavior f orm above in node.js implemented?
What I don't want to do is to have some facade / wraper with "If...." clauses which may decide who to delegeate the call
Also i want to avoid to have the setup configuration as a part of my production code. the setup code should be outside the domain logic in the Application Composition layer.
So as best thing i would have something like a component registration, and consumer which just use the registration information to get there instance (without knowing anything ábout the registration details )
i found di.js which seems to be the angular.js approach. I could also implement some kind of di by myself. But reinventing the wheel is often a bad decission.
What is the current best practice / state of the art to do this?