canister
v2.0.3
Published
A minimalist Dependency Injection container.
Downloads
35
Readme
canister
A minimalist Dependency Injection container.
Installation
This module is installed via npm:
npm install canister
Example Usage
var Canister = require('canister');
// Simple canister
var canister = new Canister(function(name) {
if (name === 'a') return [1,2];
if (name === '_') return require('lodash');
}};
// Run synchronous function
canister.run(function(a, _) {
return _.sum(a);
}, function(err, sum) {
console.log(sum);
});
// Run Asynchronous function
canister.run(function(a, cb) {
cb(null, a);
}, function(err, val) {
console.log(val);
});
// Canister with multiple resolvers with multiple types (hash, and resolver function)
var canister2 = new Canister([{a: 10}, function(name) {
if (name === 'b') return 'B';
}]);
canister2.run(function(a, b) {
console.log(a, b);
});