Comparing version 1.3.5 to 1.3.6
@@ -0,0 +0,0 @@ # Koa.js usage: |
@@ -0,0 +0,0 @@ 'use strict'; |
{ | ||
"name": "hekdi", | ||
"version": "1.3.5", | ||
"version": "1.3.6", | ||
"description": "Depedency injection framework for node.js", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -0,0 +0,0 @@ [![Build Status](https://travis-ci.org/IvanProdaiko94/hekdi.svg?branch=master)](https://travis-ci.org/IvanProdaiko94/hekdi) |
@@ -0,0 +0,0 @@ 'use strict'; |
@@ -0,0 +0,0 @@ /** |
'use strict'; | ||
const errors = require('./utils/errors'); | ||
const strategies = require('./utils/strategies'); | ||
const resolutionChecker = require('./utils/resolution_checker'); | ||
@@ -20,3 +21,3 @@ /** | ||
Injector.prototype.resolve = function(dependencyName) { | ||
if (this.dependencies.has(dependencyName)) { | ||
if (this.dependencies.has(dependencyName) && resolutionChecker.call(this, null, dependencyName)) { | ||
return this.dependencies.get(dependencyName).resolver(); | ||
@@ -63,3 +64,2 @@ } | ||
dependencies.forEach(config => { | ||
const inject = config.value.$inject || []; | ||
const dConf = this.getConfigOf(config.name); | ||
@@ -70,13 +70,3 @@ if (dConf && dConf.strategy === 'constant') { | ||
throw new Error(errors.incorrectResolutionStrategy(config.strategy, strategies)); | ||
} else if (inject.indexOf(config.name) !== -1) { | ||
throw new Error(errors.selfDependency(config.name)); | ||
} | ||
inject.forEach(dep => { | ||
if (this.dependencies.has(dep)) { | ||
const depsToCheck = this.getConfigOf(dep).value.$inject || []; | ||
if (depsToCheck.indexOf(config.name) !== -1) { | ||
throw new Error(errors.circularDependency(config.name, dep)); | ||
} | ||
} | ||
}); | ||
config.resolver = strategies[config.strategy](config.name).bind(this); | ||
@@ -83,0 +73,0 @@ config.belongTo = this.belongTo; |
@@ -0,0 +0,0 @@ 'use strict'; |
@@ -6,4 +6,3 @@ 'use strict'; | ||
unmetDependency: (moduleName, dependencyName) => `Unmet dependency '${dependencyName}' in module '${moduleName}'`, | ||
selfDependency: dependencyName => `'${dependencyName}' can't be a dependency of itself`, | ||
circularDependency: (main, dep) => `Circular dependency found in '${dep}' while registering '${main}'`, | ||
circularDependency: (list, dep) => `Circular dependency found while resolving ${dep}: ${list}`, | ||
incorrectResolutionStrategy: (strategy, strategies) => ( | ||
@@ -10,0 +9,0 @@ `strategy ${strategy} is incorrect. Allowable values are ${Object.keys(strategies).join(', ')}` |
@@ -6,5 +6,14 @@ /** | ||
const inject = function(dependencyName) { | ||
const errors = require('./errors'); | ||
const resolveHelper = function(dependencyName) { | ||
if (this.dependencies.has(dependencyName)) { | ||
return this.dependencies.get(dependencyName).resolver(); | ||
} | ||
throw new ReferenceError(errors.unmetDependency(this.belongTo, dependencyName)); | ||
}; | ||
const resolveDependency = function(dependencyName) { | ||
const config = this.getConfigOf(dependencyName); | ||
return new config.value(...(config.value.$inject || []).map(name => this.resolve(name))); | ||
return new config.value(...(config.value.$inject || []).map(name => resolveHelper.call(this, name))); | ||
}; | ||
@@ -18,3 +27,3 @@ | ||
factory: dependencyName => function() { | ||
return inject.call(this, dependencyName); | ||
return resolveDependency.call(this, dependencyName); | ||
}, | ||
@@ -29,3 +38,3 @@ /** | ||
if (!instance) { | ||
instance = inject.call(this, dependencyName); | ||
instance = resolveDependency.call(this, dependencyName); | ||
} | ||
@@ -56,4 +65,4 @@ return instance; | ||
const { name } = this.getConfigOf(value); | ||
return this.resolve(name); | ||
return resolveHelper.call(this, name); | ||
} | ||
}; |
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
14
336
18921