jaredhanson / electrolyte

Elegant dependency injection for Node.js.
MIT License
564 stars 61 forks source link

Manually register and create #31

Open uetkaje opened 9 years ago

uetkaje commented 9 years ago

Hi,

I've encountered some hassle when I use electrolyte. Here are;

var IoC = require('electrolyte');
var arg = function () {
    return 'arg';
};
arg['@singleton'] = true;
IoC.register('arg', arg);

var r = IoC.create('arg');
console.log(r);
//index.js
var IoC = require('electrolyte');
IoC.use(IoC.node('./components'));

var r1 = IoC.create('test', [
    'emre'
]);
console.log(r1);

var r2 = IoC.create('test', [
    IoC.create('arg1')
]);
console.log(r2);
//components/test.js
exports = module.exports = function (arg1) {
    return arg1;
};
exports['@require'] = ['arg1'];
exports['@singleton'] = true;
//components/arg1.js
exports = module.exports = function () {
    return 'arg1';
};
exports['@singleton'] = true;