MCPcopy Create free account
hub / github.com/angular/angular / processProvider

Method processProvider

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

* Process a `SingleProvider` and add it.

(provider: SingleProvider)

Source from the content-addressed store, hash-verified

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