MCPcopy Index your code
hub / github.com/angular/angular / R3Injector

Class R3Injector

packages/core/src/di/r3_injector.ts:191–569  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

189}
190
191export class R3Injector extends EnvironmentInjector implements PrimitivesInjector {
192 /**
193 * Map of tokens to records which contain the instances of those tokens.
194 * - `null` value implies that we don't have the record. Used by tree-shakable injectors
195 * to prevent further searches.
196 */
197 private records = new Map<ProviderToken<any>, Record<any> | null>();
198
199 /**
200 * Set of values instantiated by this injector which contain `ngOnDestroy` lifecycle hooks.
201 */
202 private _ngOnDestroyHooks = new Set<OnDestroy>();
203
204 private _onDestroyHooks: Array<() => void> = [];
205
206 /**
207 * Flag indicating that this injector was previously destroyed.
208 */
209 override get destroyed(): boolean {
210 return this._destroyed;
211 }
212 private _destroyed = false;
213
214 private injectorDefTypes: Set<Type<unknown>>;
215
216 constructor(
217 providers: Array<Provider | EnvironmentProviders>,
218 readonly parent: Injector,
219 readonly source: string | null,
220 readonly scopes: Set<InjectorScope>,
221 ) {
222 super();
223 // Start off by creating Records for every provider.
224 forEachSingleProvider(providers as Array<Provider | InternalEnvironmentProviders>, (provider) =>
225 this.processProvider(provider),
226 );
227
228 // Make sure the INJECTOR token provides this injector.
229 this.records.set(INJECTOR, makeRecord(undefined, this));
230
231 // And `EnvironmentInjector` if the current injector is supposed to be env-scoped.
232 if (scopes.has('environment')) {
233 this.records.set(EnvironmentInjector, makeRecord(undefined, this));
234 }
235
236 // Detect whether this injector has the APP_ROOT_SCOPE token and thus should provide
237 // any injectable scoped to APP_ROOT_SCOPE.
238 const record = this.records.get(INJECTOR_SCOPE) as Record<InjectorScope | null>;
239 if (record != null && typeof record.value === 'string') {
240 this.scopes.add(record.value as InjectorScope);
241 }
242
243 this.injectorDefTypes = new Set(this.get(INJECTOR_DEF_TYPES, EMPTY_ARRAY, {self: true}));
244 }
245
246 retrieve<T>(token: PrimitivesInjectionToken<T>, options?: unknown): T | NotFound {
247 const flags: InternalInjectFlags =
248 convertToBitFlags(options as InjectOptions | undefined) || InternalInjectFlags.Default;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…