Comparing version 0.2.4 to 0.2.5
@@ -31,6 +31,7 @@ // Generated by CoffeeScript 1.8.0 | ||
module.exports = Container = (function() { | ||
function Container(conf) { | ||
function Container(conf, _parent) { | ||
if (conf == null) { | ||
conf = {}; | ||
} | ||
this._parent = _parent; | ||
this._modules = conf.modules || {}; | ||
@@ -63,10 +64,22 @@ this._registrations = {}; | ||
} | ||
if (this._instances[name] == null) { | ||
this._instantiate(name); | ||
if (this._registeredAt(name) === 'local') { | ||
if (this._instances[name] == null) { | ||
this._instantiate(name); | ||
} | ||
return this._instances[name]; | ||
} else { | ||
return this._parent.get(name); | ||
} | ||
return this._instances[name]; | ||
}; | ||
Container.prototype._registeredAt = function(name) { | ||
if (this._registrations[name] != null) { | ||
return 'local'; | ||
} else if ((this._parent != null) && this._parent.isRegistered(name)) { | ||
return 'parent'; | ||
} | ||
}; | ||
Container.prototype.isRegistered = function(name) { | ||
return this._registrations[name] != null; | ||
return this._registeredAt(name) !== void 0; | ||
}; | ||
@@ -119,2 +132,4 @@ | ||
return _this._instances[d]; | ||
} else if (_this._registeredAt(d) === 'parent') { | ||
return _this._parent._instantiate(d, name); | ||
} else { | ||
@@ -121,0 +136,0 @@ return _this._instantiate(d, name); |
@@ -41,3 +41,3 @@ // Generated by CoffeeScript 1.8.0 | ||
module.exports = function(config, basePath, opts) { | ||
module.exports = function(config, basePath, opts, parent) { | ||
var di, modules; | ||
@@ -50,3 +50,3 @@ if (opts == null) { | ||
} | ||
di = new Container(opts); | ||
di = new Container(opts, parent); | ||
modules = config.modules || {}; | ||
@@ -53,0 +53,0 @@ Object.keys(modules).forEach(function(key) { |
@@ -9,8 +9,8 @@ // Generated by CoffeeScript 1.8.0 | ||
function ModuleNotFound(module, parent) { | ||
function ModuleNotFound(module, caller) { | ||
this.module = module; | ||
this.parent = parent; | ||
this.caller = caller; | ||
this.message = 'Could not find any module with name ' + module; | ||
if (this.parent != null) { | ||
this.message = this.message + ', required from module ' + this.parent; | ||
if (this.caller != null) { | ||
this.message = this.message + ', required from module ' + this.caller; | ||
} | ||
@@ -17,0 +17,0 @@ } |
{ | ||
"name": "amend", | ||
"version": "0.2.4", | ||
"version": "0.2.5", | ||
"description": "Dependency injection module and IoC container.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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
19917
270