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

Method processProvider

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

* Process a `SingleProvider` and add it.

(provider: SingleProvider)

Source from the content-addressed store, hash-verified

471 * Process a `SingleProvider` and add it.
472 */
473 private processProvider(provider: SingleProvider): void {
474 // Determine the token from the provider. Either it's its own token, or has a {provide: ...}
475 // property.
476 provider = resolveForwardRef(provider);
477 let token: any = isTypeProvider(provider)
478 ? provider
479 : resolveForwardRef(provider && provider.provide);
480
481 // Construct a `Record` for the provider.
482 const record = providerToRecord(provider);
483 if (ngDevMode) {
484 runInInjectorProfilerContext(this, token, () => {
485 // Emit InjectorProfilerEventType.Create if provider is a value provider because
486 // these are the only providers that do not go through the value hydration logic
487 // where this event would normally be emitted from.
488 if (isValueProvider(provider)) {
489 emitInjectorToCreateInstanceEvent(token);
490 emitInstanceCreatedByInjectorEvent(provider.useValue);
491 }
492
493 emitProviderConfiguredEvent(provider);
494 });
495 }
496
497 if (!isTypeProvider(provider) && provider.multi === true) {
498 // If the provider indicates that it's a multi-provider, process it specially.
499 // First check whether it's been defined already.
500 let multiRecord = this.records.get(token);
501 if (multiRecord) {
502 // It has. Throw a nice error if
503 if (ngDevMode && multiRecord.multi === undefined) {
504 throwMixedMultiProviderError();
505 }
506 } else {
507 multiRecord = makeRecord(undefined, NOT_YET, true);
508 multiRecord.factory = () => injectArgs(multiRecord!.multi!);
509 this.records.set(token, multiRecord);
510 }
511 token = provider;
512 multiRecord.multi!.push(provider);
513 } else {
514 if (ngDevMode) {
515 const existing = this.records.get(token);
516 if (existing && existing.multi !== undefined) {
517 throwMixedMultiProviderError();
518 }
519 }
520 }
521 this.records.set(token, record);
522 }
523
524 private hydrate<T>(token: ProviderToken<T>, record: Record<T>, flags: InternalInjectFlags): T {
525 const prevConsumer = setActiveConsumer(null);

Callers 1

constructorMethod · 0.95

Calls 14

resolveForwardRefFunction · 0.90
isTypeProviderFunction · 0.90
isValueProviderFunction · 0.90
injectArgsFunction · 0.90
providerToRecordFunction · 0.85
makeRecordFunction · 0.85
getMethod · 0.65

Tested by

no test coverage detected