Skip to content

Commit

Permalink
fixup! refactor(ivy): create Injector interface; remove dependency on…
Browse files Browse the repository at this point in the history
… Ivy
  • Loading branch information
mhevery committed Jan 11, 2019
1 parent 29e9f46 commit 8535148
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
47 changes: 47 additions & 0 deletions packages/core/src/di/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

/**
* @module
* @description
* The `di` module provides dependency injection container services.
*/

import {Injector as InjectorClass} from './injector';
import {Injector as InjectorInterface} from './interface';

/*
* We need to separate the Injector type from the abstract class declaration so that the type can be
* imported by Ivy without importing the `Injector` value. We could do it the normal way by changing
* the `class Injector` to just `function` but that confuses the `ngc` compiler. So instead we
* declare `Injector` twice. Once in `class Injector` and once as `interface Injector` Here we take
* the `interface Injector` type but use `class Injector` value.
*/
export type Injector = InjectorInterface;
export const Injector = InjectorClass;

/**
* Because the `class Injector` does not implement `interface Injector` (doing so would expose the
* duality to api guardian and our users) so we try to do an assignment to verify that that the two
* types match.
*/
const verify: InjectorInterface = null as any as InjectorClass;

export * from './metadata';
export {InjectableType, InjectorType, defineInjectable, defineInjector} from './interface';
export {InjectFlags} from './interface/injector';
export {forwardRef, resolveForwardRef, ForwardRefFn} from './forward_ref';
export {Injectable, InjectableDecorator, InjectableProvider} from './injectable';
export {INJECTOR} from './injector';
export {inject} from './injector_compatibility';
export {ReflectiveInjector} from './reflective_injector';
export {StaticProvider, ValueProvider, ConstructorSansProvider, ExistingProvider, FactoryProvider, Provider, TypeProvider, ClassProvider} from './interface/provider';
export {createInjector} from './r3_injector';
export {ResolvedReflectiveFactory, ResolvedReflectiveProvider} from './reflective_provider';
export {ReflectiveKey} from './reflective_key';
export {InjectionToken} from './interface/injection_token';
2 changes: 1 addition & 1 deletion packages/core/test/view/ng_module_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
*/

import {NgModuleRef} from '@angular/core';
import {InjectFlags, inject} from '@angular/core/src/di';
import {INJECTOR, Injector} from '@angular/core/src/di/injector';
import {InjectFlags, inject} from '@angular/core/src/di/injector_compatibility';
import {InjectableDef, defineInjectable} from '@angular/core/src/di/interface/defs';
import {NgModuleDefinition, NgModuleProviderDef, NodeFlags} from '@angular/core/src/view';
import {moduleDef} from '@angular/core/src/view/ng_module';
Expand Down

0 comments on commit 8535148

Please sign in to comment.