refactor(ivy): create Injector interface; remove dependency on Ivy (#28066)

This change is a prerequasity for a later change which will turn the
'di' into its own bazel package. In order to do that we have to:
- have `Injector` type be importable by Ivy. This means that we need
  to create `Injector` as a pure type in `interface` folder which is
  already a bazel package which Ivy can depend on.
- Remove the dependency of `class Injector` on Ivy so that it can be
  compiled in isolation. We do that by using `-1` as special value for
  `__NG_ELEMENT_ID__` which tells the Ivy `NodeInjector` than
  `Injector` is being requested.

PR Close #28066
This commit is contained in:
Misko Hevery
2019-01-10 23:45:02 -08:00
committed by Andrew Kushnir
parent e082fc24b2
commit fca185e191
26 changed files with 151 additions and 97 deletions

View File

@ -60,13 +60,17 @@ export class InjectionToken<T> {
providedIn?: Type<any>| 'root' | null,
factory: () => T
}) {
if (options !== undefined) {
this.ngInjectableDef = undefined;
if (typeof options == 'number') {
// This is a special hack to assign __NG_ELEMENT_ID__ to this instance.
// __NG_ELEMENT_ID__ is Used by Ivy to determine bloom filter id.
// We are using it to assign `-1` which is used to identify `Injector`.
(this as any).__NG_ELEMENT_ID__ = options;
} else if (options !== undefined) {
this.ngInjectableDef = defineInjectable({
providedIn: options.providedIn || 'root',
factory: options.factory,
});
} else {
this.ngInjectableDef = undefined;
}
}