node-lube
Simple dependency injector for node using Promises. Lifecycle of resolved components are handled by client via nesting promises or you can use a lifecycleContainer parameter to hold references to already resolved components. lube supports simple dependency checking between components, i.e. you can specify which components are required and check will fail with they are not me.
Installation
npm install lube --save
Test
npm test
Usage
Registering
To register a component:
var component = ;var container = ; container //add component to the container ; //check that all dependencies have been met
We can even register multiple components at once:
var component_a = component_b = ; var container = ; container //add components to the container ; //check that all dependencies have been met
If we want to register component with the same name as already registered:
var component_a = component_same_name_as_a = ; var container = ; container //this will throw //this will replace component_a ; //check that all dependencies have been met
Resolving
To resolve singe component:
container ;
To resolve all components matching regex:
//imagine we registered components route/a, route/b, system/xcontainer ;
Component definition
The box-standard component looks like this:
module { //returns component definition return //req is an array of required components names req: //name of this component provides: 'config' //context (this) when calling providePromise //container if it's undefined context: undefined //methood that returns promise that resolves component { //this is container as well return Promise; //returns promise that resolves the component } }
API
For complete API documentation see lube.js.
Release History
- 0.1.0 Initial release
- 0.2.0 Some more renaming from first attempt
- 0.3.0 Lifecycle support