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:
@ -7,7 +7,7 @@ import {
|
||||
print,
|
||||
IS_DART
|
||||
} from 'angular2/src/facade/lang';
|
||||
import {provide, Provider, Injector, OpaqueToken} from 'angular2/src/core/di';
|
||||
import {provide, Provider, Injector, ReflectiveInjector, OpaqueToken} from 'angular2/src/core/di';
|
||||
import {
|
||||
APP_COMPONENT_REF_PROMISE,
|
||||
APP_COMPONENT,
|
||||
@ -48,7 +48,7 @@ function _componentProviders(appComponentType: Type): Array<Type | Provider | an
|
||||
() => { appRef._unloadComponent(ref); })
|
||||
.then((componentRef) => {
|
||||
ref = componentRef;
|
||||
var testability = injector.getOptional(Testability);
|
||||
var testability = injector.get(Testability, null);
|
||||
if (isPresent(testability)) {
|
||||
injector.get(TestabilityRegistry)
|
||||
.registerApplication(componentRef.location.nativeElement, testability);
|
||||
@ -115,7 +115,7 @@ export function disposePlatform(): void {
|
||||
|
||||
function _createPlatform(providers?: Array<Type | Provider | any[]>): PlatformRef {
|
||||
_platformProviders = providers;
|
||||
let injector = Injector.resolveAndCreate(providers);
|
||||
let injector = ReflectiveInjector.resolveAndCreate(providers);
|
||||
_platform = new PlatformRef_(injector, () => {
|
||||
_platform = null;
|
||||
_platformProviders = null;
|
||||
@ -125,7 +125,7 @@ function _createPlatform(providers?: Array<Type | Provider | any[]>): PlatformRe
|
||||
}
|
||||
|
||||
function _runPlatformInitializers(injector: Injector): void {
|
||||
let inits: Function[] = <Function[]>injector.getOptional(PLATFORM_INITIALIZER);
|
||||
let inits: Function[] = <Function[]>injector.get(PLATFORM_INITIALIZER, null);
|
||||
if (isPresent(inits)) inits.forEach(init => init());
|
||||
}
|
||||
|
||||
@ -201,11 +201,11 @@ export class PlatformRef_ extends PlatformRef {
|
||||
/** @internal */
|
||||
_disposeListeners: Function[] = [];
|
||||
|
||||
constructor(private _injector: Injector, private _dispose: () => void) { super(); }
|
||||
constructor(private _injector: ReflectiveInjector, private _dispose: () => void) { super(); }
|
||||
|
||||
registerDisposeListener(dispose: () => void): void { this._disposeListeners.push(dispose); }
|
||||
|
||||
get injector(): Injector { return this._injector; }
|
||||
get injector(): ReflectiveInjector { return this._injector; }
|
||||
|
||||
application(providers: Array<Type | Provider | any[]>): ApplicationRef {
|
||||
var app = this._initApp(createNgZone(), providers);
|
||||
@ -239,7 +239,7 @@ export class PlatformRef_ extends PlatformRef {
|
||||
private _initApp(zone: NgZone,
|
||||
providers: Array<Type | Provider | any[]>): Promise<ApplicationRef>|
|
||||
ApplicationRef {
|
||||
var injector: Injector;
|
||||
var injector: ReflectiveInjector;
|
||||
var app: ApplicationRef;
|
||||
zone.run(() => {
|
||||
providers = ListWrapper.concat(providers, [
|
||||
@ -283,7 +283,7 @@ export class PlatformRef_ extends PlatformRef {
|
||||
}
|
||||
|
||||
function _runAppInitializers(injector: Injector): Promise<any> {
|
||||
let inits: Function[] = injector.getOptional(APP_INITIALIZER);
|
||||
let inits: Function[] = injector.get(APP_INITIALIZER, null);
|
||||
let promises: Promise<any>[] = [];
|
||||
if (isPresent(inits)) {
|
||||
inits.forEach(init => {
|
||||
@ -390,7 +390,8 @@ export class ApplicationRef_ extends ApplicationRef {
|
||||
/** @internal */
|
||||
private _enforceNoNewChanges: boolean = false;
|
||||
|
||||
constructor(private _platform: PlatformRef_, private _zone: NgZone, private _injector: Injector) {
|
||||
constructor(private _platform: PlatformRef_, private _zone: NgZone,
|
||||
private _injector: ReflectiveInjector) {
|
||||
super();
|
||||
if (isPresent(this._zone)) {
|
||||
ObservableWrapper.subscribe(this._zone.onMicrotaskEmpty,
|
||||
|
Reference in New Issue
Block a user