aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMisko Hevery2011-10-25 21:28:48 -0700
committerMisko Hevery2011-11-14 16:39:32 -0800
commit03dd8c4f4c462cb5a5a08faf3cca6946dd3815f2 (patch)
treeae2e881e53210c6cff3f9788ecc4a8256d30abcc
parent48697a2b86dbb12ea8de64cc5fece7caf68b321e (diff)
downloadangular.js-03dd8c4f4c462cb5a5a08faf3cca6946dd3815f2.tar.bz2
feat(injector): Service look up failures include dependency path
-rw-r--r--src/Injector.js19
-rw-r--r--test/InjectorSpec.js8
2 files changed, 18 insertions, 9 deletions
diff --git a/src/Injector.js b/src/Injector.js
index ae584364..a3ce7f10 100644
--- a/src/Injector.js
+++ b/src/Injector.js
@@ -44,22 +44,25 @@ function createInjector(factories) {
});
return injector;
- function injector(value){
- if (!(value in instanceCache)) {
- var factory = factories[value];
- if (!factory) throw Error("Unknown provider for '" + value + "'.");
+ function injector(serviceId, path){
+ if (!(serviceId in instanceCache)) {
+ var factory = factories[serviceId];
+ path = path || [];
+ path.unshift(serviceId);
+ if (!factory) throw Error("Unknown provider for '" + path.join("' <- '") + "'.");
inferInjectionArgs(factory);
- instanceCache[value] = invoke(null, factory);
+ instanceCache[serviceId] = invoke(null, factory, [], path);
+ path.shift();
}
- return instanceCache[value];
+ return instanceCache[serviceId];
}
- function invoke(self, fn, args){
+ function invoke(self, fn, args, path){
args = args || [];
var injectNames = fn.$inject || [];
var i = injectNames.length;
while(i--) {
- args.unshift(injector(injectNames[i]));
+ args.unshift(injector(injectNames[i], path));
}
return fn.apply(self, args);
}
diff --git a/test/InjectorSpec.js b/test/InjectorSpec.js
index 39b20392..fe1993e5 100644
--- a/test/InjectorSpec.js
+++ b/test/InjectorSpec.js
@@ -62,12 +62,18 @@ describe('injector', function() {
});
- it('should provide usefull message if no provider', function() {
+ it('should provide useful message if no provider', function() {
expect(function() {
injector('idontexist');
}).toThrow("Unknown provider for 'idontexist'.");
});
+ it('should proved path to the missing provider', function(){
+ expect(function() {
+ injector('idontexist', ['a', 'b']);
+ }).toThrow("Unknown provider for 'idontexist' <- 'a' <- 'b'.");
+ });
+
it('should autostart eager services', function() {
var log = '';
providers('eager', function() {log += 'eager;'; return 'foo';}, {$eager: true});