refactor(core): separate reflective injector from Injector interface

BREAKING CHANGE:
- Injector was renamed into `ReflectiveInjector`,
  as `Injector` is only an abstract class with one method on it
- `Injector.getOptional()` was changed into `Injector.get(token, notFoundValue)`
  to make implementing injectors simpler
- `ViewContainerRef.createComponent` now takes an `Injector`
  instead of `ResolvedProviders`. If a reflective injector
  should be used, create one before calling this method.
  (e.g. via `ReflectiveInjector.resolveAndCreate(…)`.
This commit is contained in:
Tobias Bosch
2016-04-14 12:35:24 -07:00
parent efbd446d18
commit 0a7d10ba55
46 changed files with 1790 additions and 1719 deletions

View File

@ -1,4 +1,4 @@
import {Injector, Provider, PLATFORM_INITIALIZER} from 'angular2/core';
import {ReflectiveInjector, Provider, PLATFORM_INITIALIZER} from 'angular2/core';
import {BaseException, ExceptionHandler} from 'angular2/src/facade/exceptions';
import {ListWrapper} from 'angular2/src/facade/collection';
import {FunctionWrapper, isPresent, Type} from 'angular2/src/facade/lang';
@ -6,7 +6,7 @@ import {FunctionWrapper, isPresent, Type} from 'angular2/src/facade/lang';
export class TestInjector {
private _instantiated: boolean = false;
private _injector: Injector = null;
private _injector: ReflectiveInjector = null;
private _providers: Array<Type | Provider | any[]> = [];
@ -28,7 +28,7 @@ export class TestInjector {
}
createInjector() {
var rootInjector = Injector.resolveAndCreate(this.platformProviders);
var rootInjector = ReflectiveInjector.resolveAndCreate(this.platformProviders);
this._injector = rootInjector.resolveAndCreateChild(
ListWrapper.concat(this.applicationProviders, this._providers));
this._instantiated = true;
@ -76,7 +76,7 @@ export function setBaseTestProviders(platformProviders: Array<Type | Provider |
testInjector.platformProviders = platformProviders;
testInjector.applicationProviders = applicationProviders;
var injector = testInjector.createInjector();
let inits: Function[] = injector.getOptional(PLATFORM_INITIALIZER);
let inits: Function[] = injector.get(PLATFORM_INITIALIZER, null);
if (isPresent(inits)) {
inits.forEach(init => init());
}
@ -201,7 +201,7 @@ export class FunctionWithParamTokens {
/**
* Returns the value of the executed function.
*/
execute(injector: Injector): any {
execute(injector: ReflectiveInjector): any {
var params = this._tokens.map(t => injector.get(t));
return FunctionWrapper.apply(this._fn, params);
}