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

Method resolveParam

packages/core/injector/injector.ts:340–412  ·  view source on GitHub ↗
(param: unknown, index: number)

Source from the content-addressed store, hash-verified

338 const paramBarrier = new Barrier(dependencies.length);
339 let isResolved = true;
340 const resolveParam = async (param: unknown, index: number) => {
341 try {
342 if (this.isInquirer(param, parentInquirer)) {
343 /*
344 * Signal the barrier to make sure other dependencies do not get stuck waiting forever.
345 */
346 paramBarrier.signal();
347
348 return parentInquirer && parentInquirer.instance;
349 }
350 if (resolutionContext.inquirer?.isTransient && parentInquirer) {
351 // When `inquirer` is transient too, inherit the parent inquirer
352 // This is required to ensure that transient providers are only resolved
353 // when requested
354 resolutionContext.inquirer.attachRootInquirer(parentInquirer);
355 }
356 const nestedResolutionContext =
357 this.getStaticTransientResolutionContext(
358 resolutionContext,
359 parentInquirer,
360 );
361 const paramWrapper = await this.resolveSingleParam<T>(
362 wrapper,
363 param as Type | string | symbol,
364 { index, dependencies },
365 moduleRef,
366 nestedResolutionContext,
367 index,
368 );
369
370 /*
371 * Ensure that all instance wrappers are resolved at this point before we continue.
372 * Otherwise the staticity of `wrapper`'s dependency tree may be evaluated incorrectly
373 * and result in undefined / null injection.
374 */
375 await paramBarrier.signalAndWait();
376
377 const effectiveResolutionContext = this.getEffectiveResolutionContext(
378 paramWrapper,
379 resolutionContext,
380 parentInquirer,
381 );
382 const paramWrapperWithInstance = await this.resolveComponentHost(
383 moduleRef,
384 paramWrapper,
385 effectiveResolutionContext,
386 );
387 const instanceHost = paramWrapperWithInstance.getInstanceByContextId(
388 this.getContextId(
389 effectiveResolutionContext.contextId,
390 paramWrapperWithInstance,
391 ),
392 effectiveResolutionContext.effectiveInquirerId,
393 );
394 if (!instanceHost.isResolved && !paramWrapperWithInstance.forwardRef) {
395 isResolved = false;
396 }
397 return instanceHost?.instance;

Callers

nothing calls this directly

Calls 9

isInquirerMethod · 0.95
resolveComponentHostMethod · 0.95
getContextIdMethod · 0.95
signalMethod · 0.80
attachRootInquirerMethod · 0.80
signalAndWaitMethod · 0.80

Tested by

no test coverage detected