dependency-injection
Advanced tools
Comparing version 1.2.0 to 1.2.1
// Generated by CoffeeScript 1.6.3 | ||
(function() { | ||
var DI, Service; | ||
var DI, Service, | ||
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; | ||
@@ -10,2 +11,4 @@ Service = require('./Service'); | ||
DI.prototype.reserved = ['di']; | ||
function DI() { | ||
@@ -19,2 +22,5 @@ this.services = {}; | ||
} | ||
if (__indexOf.call(this.reserved, name) >= 0) { | ||
throw new Error("DI: name '" + name + "' is reserved by DI"); | ||
} | ||
this.services[name] = new Service(this, service, args); | ||
@@ -25,3 +31,4 @@ return this.services[name]; | ||
DI.prototype.autowireArguments = function(method, args) { | ||
var arg, factory, i, methodArgs, result, _i, _len; | ||
var arg, factory, i, methodArgs, result, self, _i, _len, | ||
_this = this; | ||
if (args == null) { | ||
@@ -43,3 +50,8 @@ args = []; | ||
} | ||
if (this.findDefinitionByName(arg).autowired === false) { | ||
if (arg === 'di') { | ||
self = factory === true ? function() { | ||
return _this; | ||
} : this; | ||
result.push(self); | ||
} else if (this.findDefinitionByName(arg).autowired === false) { | ||
throw new Error("DI: service " + arg + " can not be autowired"); | ||
@@ -46,0 +58,0 @@ } else if (factory === true) { |
{ | ||
"name": "dependency-injection", | ||
"description": "Dependency injection with configuration and autowire for node js and browser", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "David Kudera", |
@@ -135,2 +135,7 @@ # Dependency injection | ||
## Autowiring DI | ||
Autowiring DI container is also possible. Only thing you need to do, is set argument with name "di" into your method or | ||
constructor. This also means that you can not register new service with name "di". | ||
## Inject methods | ||
@@ -182,2 +187,5 @@ | ||
* 1.2.1 | ||
+ Added ability to inject DI container itself | ||
* 1.2.0 | ||
@@ -184,0 +192,0 @@ + Added DI.createInstance method |
@@ -16,2 +16,4 @@ // Generated by CoffeeScript 1.6.3 | ||
Application.prototype.di = null; | ||
function Application(array) { | ||
@@ -38,2 +40,6 @@ this.array = array; | ||
Application.prototype.setDi = function(di) { | ||
this.di = di; | ||
}; | ||
return Application; | ||
@@ -40,0 +46,0 @@ |
@@ -29,5 +29,10 @@ // Generated by CoffeeScript 1.6.3 | ||
}); | ||
return it('should return instance of new Service class from path', function() { | ||
it('should return instance of new Service class from path', function() { | ||
return di.addService('app', "" + dir + "/Application").should.be.instanceOf(Service); | ||
}); | ||
return it('should throw an error if you try to register service with reserved name', function() { | ||
return (function() { | ||
return di.addService('di', DI); | ||
}).should["throw"](); | ||
}); | ||
}); | ||
@@ -111,4 +116,4 @@ describe('#autowireArguments()', function() { | ||
}); | ||
return it('should not set services which are not autowired', function() { | ||
di.findDefinitionByName('application').addSetup('setData', []); | ||
it('should not set services which are not autowired', function() { | ||
di.findDefinitionByName('application').addSetup('setData'); | ||
return (function() { | ||
@@ -118,2 +123,6 @@ return di.getByName('application'); | ||
}); | ||
return it('should autowire di container into Application instance', function() { | ||
di.findDefinitionByName('application').addSetup('setDi'); | ||
return di.getByName('application').di.should.be.equal(di); | ||
}); | ||
}); | ||
@@ -120,0 +129,0 @@ describe('#create()', function() { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
30901
400
208