Is it possible to embed dependencies in ES2015 modules, for example, in other programming languages ββsuch as C # or Java? If I import a module, I create a hard dependency for it and cannot change it later at runtime. For example, I have the following JavaScript code:
import Animal from './dog'; class Person { feedAnimal() { new Animal().feed(); } }
I import a dog module. But what if I want to change it to a cat? At the moment, I need to change line 1 manually, but in some situations I want it to be configured externally, so under certain conditions there should be a cat, and in some other conditions it should be a cat. Everything you can do with classic dependency injection.
I know that there are some DI frameworks, for example Scatter , Electrolyte , Wire , etc., but, unfortunately, most of them require special syntax and are not made for ES2015 modules .
javascript ecmascript-6 dependency-injection es6-module-loader
Longflick
source share