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

Method select

packages/core/nest-application-context.ts:92–130  ·  view source on GitHub ↗

* Allows navigating through the modules tree, for example, to pull out a specific instance from the selected module. * @returns {INestApplicationContext}

(
    moduleType: Type<T> | DynamicModule,
    selectOptions?: SelectOptions,
  )

Source from the content-addressed store, hash-verified

90 * @returns {INestApplicationContext}
91 */
92 public select<T>(
93 moduleType: Type<T> | DynamicModule,
94 selectOptions?: SelectOptions,
95 ): INestApplicationContext {
96 const modulesContainer = this.container.getModules();
97 const contextModuleCtor = this.contextModule!.metatype;
98 const scope = this.scope.concat(contextModuleCtor);
99
100 const moduleTokenFactory = this.container.getModuleTokenFactory();
101 const { type, dynamicMetadata } =
102 this.moduleCompiler.extractMetadata(moduleType);
103 const token = dynamicMetadata
104 ? moduleTokenFactory.createForDynamic(
105 type,
106 dynamicMetadata,
107 moduleType as DynamicModule,
108 )
109 : moduleTokenFactory.createForStatic(type, moduleType as Type);
110
111 const selectedModule = modulesContainer.get(token);
112 if (!selectedModule) {
113 throw new UnknownModuleException(type.name);
114 }
115
116 const options =
117 typeof selectOptions?.abortOnError !== 'undefined'
118 ? {
119 ...this.appOptions,
120 ...selectOptions,
121 }
122 : this.appOptions;
123
124 return new NestApplicationContext(
125 this.container,
126 options,
127 selectedModule,
128 scope,
129 );
130 }
131
132 /**
133 * Retrieves an instance of either injectable or controller, otherwise, throws exception.

Callers

nothing calls this directly

Calls 6

getModuleTokenFactoryMethod · 0.80
extractMetadataMethod · 0.80
createForDynamicMethod · 0.65
createForStaticMethod · 0.65
getMethod · 0.65
getModulesMethod · 0.45

Tested by

no test coverage detected