Sixphere - Dependency Injector Wrapper
Dependency injection lightweight library that allows you inject any service instance in any class in a fast and easy way.
Install
npm install '@sixphere/diwrapper' --save
How to use?
The centerpiece of the dependency injector is the __inject
method. Your class must implement a method with this name and the needed arguments. The library use this method to inject the builded instances.
// dummy-component.js
class DummyComponent {
//...
__inject(dummyService1, dummyService2) {
this.dummyService1 = dummyService1
this.dummyService2 = dummyService2
}
//...
}
Bind dependencies
Import the dependency injector wrapper.
import { DIWrapper } from '@sixphere/diwrapper'
Specify the class and his dependecies.
// index.js
let ComposedDummyComponent = DIWrapper.for(DummyComponent).bind([
{ constructor: DummyService1, args: [] },
{ constructor: DummyService2, args: [] },
])
License
MIT License © 2019 Sixphere