refactor(di): move all binding resolution logic into injector.js

This commit is contained in:
Yegor Jbanov
2015-04-13 14:29:32 -07:00
parent c5c1c9e38e
commit 3667854a8f
2 changed files with 28 additions and 27 deletions

View File

@ -3,7 +3,7 @@ import {List, MapWrapper, ListWrapper} from 'angular2/src/facade/collection';
import {reflector} from 'angular2/src/reflection/reflection';
import {Key} from './key';
import {Inject, InjectLazy, InjectPromise, Optional, DependencyAnnotation} from './annotations';
import {NoAnnotationError, InvalidBindingError} from './exceptions';
import {NoAnnotationError} from './exceptions';
export class Dependency {
key:Key;
@ -88,29 +88,6 @@ export class Binding {
isAsync
);
}
static resolveAll(bindings:List): List {
var resolvedList = ListWrapper.createFixedSize(bindings.length);
for (var i = 0; i < bindings.length; i++) {
var unresolved = bindings[i];
var resolved;
if (unresolved instanceof ResolvedBinding) {
resolved = unresolved; // ha-ha! I'm easily amused
} else if (unresolved instanceof Type) {
resolved = bind(unresolved).toClass(unresolved).resolve();
} else if (unresolved instanceof Binding) {
resolved = unresolved.resolve();
} else if (unresolved instanceof List) {
resolved = Binding.resolveAll(unresolved);
} else if (unresolved instanceof BindingBuilder) {
throw new InvalidBindingError(unresolved.token);
} else {
throw new InvalidBindingError(unresolved);
}
resolvedList[i] = resolved;
}
return resolvedList;
}
}
/// Dependency binding with resolved keys and dependencies.