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

Method resolveConstructorParams

packages/core/injector/injector.ts:310–415  ·  view source on GitHub ↗
(
    wrapper: InstanceWrapper<T>,
    moduleRef: Module,
    inject: InjectorDependency[] | undefined,
    callback: (args: unknown[]) => void | Promise<void>,
    resolutionContext: ResolutionContext = { contextId: STATIC_CONTEXT },
    parentInquirer?: InstanceWrapper,
  )

Source from the content-addressed store, hash-verified

308 }
309
310 public async resolveConstructorParams<T>(
311 wrapper: InstanceWrapper<T>,
312 moduleRef: Module,
313 inject: InjectorDependency[] | undefined,
314 callback: (args: unknown[]) => void | Promise<void>,
315 resolutionContext: ResolutionContext = { contextId: STATIC_CONTEXT },
316 parentInquirer?: InstanceWrapper,
317 ) {
318 const metadata = wrapper.getCtorMetadata();
319
320 if (
321 resolutionContext.contextId !== STATIC_CONTEXT &&
322 this.hasDenseCtorMetadata(wrapper, inject, metadata)
323 ) {
324 const deps = await this.loadCtorMetadata(
325 metadata,
326 resolutionContext.contextId,
327 resolutionContext.inquirer,
328 parentInquirer,
329 );
330 return callback(deps);
331 }
332
333 const isFactoryProvider = !isNil(inject);
334 const [dependencies, optionalDependenciesIds] = isFactoryProvider
335 ? this.getFactoryProviderDependencies(wrapper)
336 : this.getClassDependencies(wrapper);
337
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,

Callers 1

injector.spec.tsFile · 0.80

Calls 8

hasDenseCtorMetadataMethod · 0.95
loadCtorMetadataMethod · 0.95
getClassDependenciesMethod · 0.95
isNilFunction · 0.90
getCtorMetadataMethod · 0.80
allMethod · 0.80
callbackFunction · 0.70

Tested by

no test coverage detected