MCPcopy
hub / github.com/nestjs/nest / resolveComponentHost

Method resolveComponentHost

packages/core/injector/injector.ts:546–600  ·  view source on GitHub ↗
(
    moduleRef: Module,
    instanceWrapper: InstanceWrapper<T | Promise<T>>,
    resolutionContext: ResolutionContext = { contextId: STATIC_CONTEXT },
  )

Source from the content-addressed store, hash-verified

544 }
545
546 public async resolveComponentHost<T>(
547 moduleRef: Module,
548 instanceWrapper: InstanceWrapper<T | Promise<T>>,
549 resolutionContext: ResolutionContext = { contextId: STATIC_CONTEXT },
550 ): Promise<InstanceWrapper> {
551 const inquirerId = this.getContextInquirerId(resolutionContext);
552 const instanceHost = instanceWrapper.getInstanceByContextId(
553 this.getContextId(resolutionContext.contextId, instanceWrapper),
554 inquirerId,
555 );
556 if (!instanceHost.isResolved && !instanceWrapper.forwardRef) {
557 resolutionContext.inquirer?.settlementSignal?.insertRef(
558 instanceWrapper.id,
559 );
560
561 await this.loadProvider(
562 instanceWrapper,
563 instanceWrapper.host ?? moduleRef,
564 resolutionContext,
565 );
566 } else if (
567 !instanceHost.isResolved &&
568 instanceWrapper.forwardRef &&
569 (resolutionContext.contextId !== STATIC_CONTEXT || !!inquirerId)
570 ) {
571 /**
572 * When circular dependency has been detected between
573 * either request/transient providers, we have to asynchronously
574 * resolve instance host for a specific contextId or inquirer, to ensure
575 * that eventual lazily created instance will be merged with the prototype
576 * instantiated beforehand.
577 */
578 instanceHost.donePromise &&
579 void instanceHost.donePromise
580 .then(() =>
581 this.loadProvider(instanceWrapper, moduleRef, resolutionContext),
582 )
583 .catch(err => {
584 instanceWrapper.settlementSignal?.error(err);
585 });
586 }
587 if (instanceWrapper.async) {
588 const host = instanceWrapper.getInstanceByContextId(
589 this.getContextId(resolutionContext.contextId, instanceWrapper),
590 inquirerId,
591 );
592 host.instance = await host.instance;
593 instanceWrapper.setInstanceByContextId(
594 resolutionContext.contextId,
595 host,
596 inquirerId,
597 );
598 }
599 return instanceWrapper;
600 }
601
602 public async lookupComponent<T = any>(
603 providers: Map<Function | string | symbol, InstanceWrapper>,

Callers 5

resolveParamMethod · 0.95
resolvePropertiesMethod · 0.95
injector.spec.tsFile · 0.45

Calls 8

getContextInquirerIdMethod · 0.95
getContextIdMethod · 0.95
loadProviderMethod · 0.95
insertRefMethod · 0.80
catchMethod · 0.65
errorMethod · 0.65

Tested by

no test coverage detected