covannan
v1.1.1
Published
covannan is dead simple constructor injection that know how to load dependencies for you.
Downloads
9
Readme
covannan
covannan is dead simple constructor injection that know how to load dependencies for you.
Installation
npm install covannan
Example
/* app.js */
var covannan = require('covannan')();
// you can set value as a string, object, array
covannan.set('rootPath', __dirname);
// or set value as a function
// sugar: no need to thinking about dependencies here.
covannan.set('user', require('./lib/user'));
covannan.set('auth', require('./lib/auth'));
/* .lib/user/index.js */
module.exports = function (auth) {
// here in our user module, we depend on auth
// convannan will inject auth module for us
auth.login();
}
// .lib/auth/index.js
module.exports = function () {
return {
login: function() { /* do login */ }
}
}
// more sugar for lazy dudes
convannan.autoload('/lib/**/*.js');
Usage
covannan.set(name, value);
covannan.get(name);
covannan.autoload(pattern);
Constructor Injection
if value is a function, covannan will auto resolve dependencies and passing them to contructor as arguments.
covannan.set('cal.add', function(a,b) { return a+b });
covannan.set('a', 1);
covannan.set('b', 2);
covannan.get('cal.add'); // 3
API
.set(name, value)
creates a dependency name
.get(name, value)
and load it back
.autoload(path)
autoload all files in path
as dependencies