refactor(di): simplify Injector API

This commit is contained in:
vsavkin 2014-10-10 16:31:27 -04:00
parent f0870791f6
commit c3d9b5c91e
3 changed files with 8 additions and 10 deletions

View File

@ -30,19 +30,11 @@ export class Injector {
} }
get(token) { get(token) {
return this.getByKey(Key.get(token)); return this._getByKey(Key.get(token), false, false);
} }
asyncGet(token) { asyncGet(token) {
return this.asyncGetByKey(Key.get(token)); return this._getByKey(Key.get(token), true, false);
}
getByKey(key:Key) {
return this._getByKey(key, false, false);
}
asyncGetByKey(key:Key) {
return this._getByKey(key, true, false);
} }
createChild(bindings:List):Injector { createChild(bindings:List):Injector {

View File

@ -13,6 +13,8 @@ export class Key {
} }
static get(token) { static get(token) {
if (token instanceof Key) return token;
if (MapWrapper.contains(_allKeys, token)) { if (MapWrapper.contains(_allKeys, token)) {
return MapWrapper.get(_allKeys, token) return MapWrapper.get(_allKeys, token)
} }

View File

@ -10,5 +10,9 @@ export function main() {
it('should not be equal to another key if types are different', function () { it('should not be equal to another key if types are different', function () {
expect(Key.get('car')).not.toBe(Key.get('porsche')); expect(Key.get('car')).not.toBe(Key.get('porsche'));
}); });
it('should return the passed in key', function () {
expect(Key.get(Key.get('car'))).toBe(Key.get('car'));
});
}); });
} }