Kevin 29b9a0c50c clean && clean html base 4 years ago
..
lib 29b9a0c50c clean && clean html base 4 years ago
src 29b9a0c50c clean && clean html base 4 years ago
tests 29b9a0c50c clean && clean html base 4 years ago
.npmignore 29b9a0c50c clean && clean html base 4 years ago
.travis.yml 29b9a0c50c clean && clean html base 4 years ago
LICENSE 29b9a0c50c clean && clean html base 4 years ago
README.md 29b9a0c50c clean && clean html base 4 years ago
coffeelint.json 29b9a0c50c clean && clean html base 4 years ago
gulpfile.coffee 29b9a0c50c clean && clean html base 4 years ago
gulpfile.js 29b9a0c50c clean && clean html base 4 years ago
package.json 29b9a0c50c clean && clean html base 4 years ago

README.md

Simple Dependency Injection for NodeJS

Build Status

NPM

What this?

This lib provides Dependency Injection to NodeJS by super-simple approach.

How to install

Just run npm install kissdi

How to use

Also just simple!

// kissdi has a function named 'inject' as library's member.
inject = require("node-kissdi").inject
/*
 * To inject a function, we need to create a "target function"
 * the target function should be an instance of Array that has a function as
 * a last element. i.e.
 */
var target = [
    "foo",
    "bar",
    function (foo, bar) {
        return function () {
            return [foo, bar];
        };
    }
];

// Then, call inject like this
var injected_func = inject(
    target,
    {
        "foo": "Hello",
        "bar": "World"
    }
);

// To obtain the return value from the target, call inject_func.invoke
var func = inject_func.invoke();
// Because the target function is a closure, we need to call it once more.
// Therefore, needs to call func if we obtain the result list
var list = func()
// expect: ["Hello", "World"]

// Calling invoke with an object that has corresponding paramenters as keys,
// the corresponding parameters are replaced with the given values.
var func = inject_func.invoke({
   "foo": "Konichiwa"
});
// func() returns ["Konichiwa", "World"]
var list = func()
// expect: ["Konichiwa", "World"]