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

Method addModule

packages/core/injector/container.ts:92–127  ·  view source on GitHub ↗
(
    metatype: ModuleMetatype,
    scope: ModuleScope,
  )

Source from the content-addressed store, hash-verified

90 }
91
92 public async addModule(
93 metatype: ModuleMetatype,
94 scope: ModuleScope,
95 ): Promise<
96 | {
97 moduleRef: Module;
98 inserted: boolean;
99 }
100 | undefined
101 > {
102 // In DependenciesScanner#scanForModules we already check for undefined or invalid modules
103 // We still need to catch the edge-case of `forwardRef(() => undefined)`
104 if (!metatype) {
105 throw new UndefinedForwardRefException(scope);
106 }
107 const { type, dynamicMetadata, token } =
108 await this.moduleCompiler.compile(metatype);
109 if (this.modules.has(token)) {
110 return {
111 moduleRef: this.modules.get(token)!,
112 inserted: true,
113 };
114 }
115
116 return {
117 moduleRef: await this.setModule(
118 {
119 token,
120 type,
121 dynamicMetadata,
122 },
123 scope,
124 ),
125 inserted: true,
126 };
127 }
128
129 public async replaceModule(
130 metatypeToReplace: ModuleMetatype,

Callers 9

addDynamicModulesMethod · 0.95
testHelperFunction · 0.95
insertModuleMethod · 0.80
injector.spec.tsFile · 0.80
container.spec.tsFile · 0.80

Calls 4

setModuleMethod · 0.95
hasMethod · 0.80
getMethod · 0.65
compileMethod · 0.45

Tested by 1

testHelperFunction · 0.76