handbag
A simple Dependency Injection container written in ES6.
Some ideas were taken from AngularJS' $injector
service.
- Allow to nest injectors so you can separate containers by module, package, etc
- Accepts a
Symbol
as a provider or constant name. - Allows only a provider (factory function or class) and constants
- Allows to register a "private" provider, i.e. a factory that will NOT be a singleton
- Allows to freeze the container (disables any further changes in the dependencies)
Injector API
- .constant(name, value)
- .provide(name, provider, isShared = true)
- .provideShared(name, provider);
- .provideNotShared(name, provider);
- .has(name)
- .get(name, locals = {})
- .freeze()
Static methods
- .createInjector()
Usage
See the full API on documentation page
// foo.service.js const FOO = 123; { thisfoo = FOO; } ; // foo.controller.js { thisservice = FooService; thisdata = data } // app.js ;;; const di = handbag; di;di;di; // instantiates FooController injecting the service on constructorconst data = bar: 1 ;const ctrl = di;