feat(injector): support forwardRef in toAlias
This commit is contained in:
parent
705ee46f31
commit
fed86fc8ac
|
@ -236,8 +236,7 @@ export class Binding {
|
||||||
resolvedDeps = _EMPTY_LIST;
|
resolvedDeps = _EMPTY_LIST;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ResolvedBinding(Key.get(resolveForwardRef(this.token)), factoryFn, resolvedDeps,
|
return new ResolvedBinding(Key.get(this.token), factoryFn, resolvedDeps, isAsync);
|
||||||
isAsync);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -492,5 +491,5 @@ function _extractToken(typeOrFunc, annotations) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function _createDependency(token, asPromise, lazy, optional, depProps): Dependency {
|
function _createDependency(token, asPromise, lazy, optional, depProps): Dependency {
|
||||||
return new Dependency(Key.get(resolveForwardRef(token)), asPromise, lazy, optional, depProps);
|
return new Dependency(Key.get(token), asPromise, lazy, optional, depProps);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
library angular2.di.forward_ref;
|
library angular2.di.forward_ref;
|
||||||
|
|
||||||
typedef Type ForwardRefFn();
|
typedef dynamic ForwardRefFn();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dart does not have the forward ref problem, so this function is a noop.
|
* Dart does not have the forward ref problem, so this function is a noop.
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import {MapWrapper} from 'angular2/src/facade/collection';
|
import {MapWrapper} from 'angular2/src/facade/collection';
|
||||||
import {stringify, CONST, Type, isBlank, BaseException} from 'angular2/src/facade/lang';
|
import {stringify, CONST, Type, isBlank, BaseException} from 'angular2/src/facade/lang';
|
||||||
import {TypeLiteral} from './type_literal';
|
import {TypeLiteral} from './type_literal';
|
||||||
|
import {resolveForwardRef} from './forward_ref';
|
||||||
|
|
||||||
export {TypeLiteral} from './type_literal';
|
export {TypeLiteral} from './type_literal';
|
||||||
|
|
||||||
|
@ -38,7 +39,7 @@ export class Key {
|
||||||
/**
|
/**
|
||||||
* Retrieves a `Key` for a token.
|
* Retrieves a `Key` for a token.
|
||||||
*/
|
*/
|
||||||
static get(token): Key { return _globalKeyRegistry.get(token); }
|
static get(token): Key { return _globalKeyRegistry.get(resolveForwardRef(token)); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns the number of keys registered in the system.
|
* @returns the number of keys registered in the system.
|
||||||
|
|
|
@ -162,6 +162,14 @@ export function main() {
|
||||||
expect(() => injector.get('car')).toThrowError('No provider for SportsCar! (car -> SportsCar)');
|
expect(() => injector.get('car')).toThrowError('No provider for SportsCar! (car -> SportsCar)');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should handle forwardRef in toAlias', function () {
|
||||||
|
var injector = Injector.resolveAndCreate([
|
||||||
|
bind('originalEngine').toClass(forwardRef(() => Engine)),
|
||||||
|
bind('aliasedEngine').toAlias(forwardRef(() => 'originalEngine'))
|
||||||
|
]);
|
||||||
|
expect(injector.get('aliasedEngine')).toBeAnInstanceOf(Engine);
|
||||||
|
});
|
||||||
|
|
||||||
it('should support overriding factory dependencies', function () {
|
it('should support overriding factory dependencies', function () {
|
||||||
var injector = Injector.resolveAndCreate([
|
var injector = Injector.resolveAndCreate([
|
||||||
Engine,
|
Engine,
|
||||||
|
|
Loading…
Reference in New Issue