es6-dic
ES6 Dependency Injection Container
Install
$ npm install es6-dic
Usage
; var c = ; c;c; console // 'ba';
API
.register(name, [dependencies,] factory)
Register name
with optional dependencies
.
factory
is used to create instance,
the arguments are the specified dependencies.
Dependency order is important.
.resolve(name)
Get instance for name
.
Notes
"But how can I run this?!"
Well, I use it with browserify & es6ify. It should work with traceur, but afaik module import/export is not compatible with node.
"But I need circular dependencies!!4"
Well, register the container itself as a dependency, and resolve the needed module in runtime!
var c = ; c; c; c; c;
"But I need multiple instances, not singletons!"
Well, then don't return instance in the factory
!
c; c;
A more complex example:
{ thisstuff = stuff; } { console } c; c;c; c; c; // 1, 2, 3 \o/ yay!
"Tests?!"
Eeerrr, run them with browserify :S, not very node-friendy. If you have a better solution, please create an issue!
License
MIT