Skip to content

Commit e9624b9

Browse files
fix(core): fix app.select method (share token factory)
1 parent c64cde1 commit e9624b9

3 files changed

Lines changed: 18 additions & 12 deletions

File tree

packages/core/injector/compiler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export interface ModuleFactory {
88
}
99

1010
export class ModuleCompiler {
11-
private readonly moduleTokenFactory = new ModuleTokenFactory();
11+
constructor(private readonly moduleTokenFactory = new ModuleTokenFactory()) {}
1212

1313
public async compile(
1414
metatype: Type<any> | DynamicModule | Promise<DynamicModule>,

packages/core/injector/container.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ import { ModuleCompiler } from './compiler';
1212
import { InternalCoreModule } from './internal-core-module';
1313
import { InternalProvidersStorage } from './internal-providers-storage';
1414
import { Module } from './module';
15+
import { ModuleTokenFactory } from './module-token-factory';
1516
import { ModulesContainer } from './modules-container';
1617

1718
export class NestContainer {
1819
private readonly globalModules = new Set<Module>();
19-
private readonly moduleCompiler = new ModuleCompiler();
20+
private readonly moduleTokenFactory = new ModuleTokenFactory();
21+
private readonly moduleCompiler = new ModuleCompiler(this.moduleTokenFactory);
2022
private readonly modules = new ModulesContainer();
2123
private readonly dynamicModulesMetadata = new Map<
2224
string,
@@ -115,8 +117,9 @@ export class NestContainer {
115117
relatedModule: Type<any> | DynamicModule,
116118
token: string,
117119
) {
118-
if (!this.modules.has(token)) return;
119-
120+
if (!this.modules.has(token)) {
121+
return;
122+
}
120123
const module = this.modules.get(token);
121124
const parent = module.metatype;
122125

@@ -222,4 +225,8 @@ export class NestContainer {
222225
this.internalCoreModule = moduleRef;
223226
this.modules[InternalCoreModule.name] = moduleRef;
224227
}
228+
229+
public getModuleTokenFactory(): ModuleTokenFactory {
230+
return this.moduleTokenFactory;
231+
}
225232
}

packages/core/nest-application-context.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import {
22
INestApplicationContext,
3+
Logger,
34
LoggerService,
45
ShutdownSignal,
56
} from '@nestjs/common';
6-
import { Logger } from '@nestjs/common';
77
import { Abstract } from '@nestjs/common/interfaces';
88
import { Type } from '@nestjs/common/interfaces/type.interface';
99
import { isEmpty } from '@nestjs/common/utils/shared.utils';
10+
import { MESSAGES } from './constants';
1011
import { UnknownElementException } from './errors/exceptions/unknown-element.exception';
1112
import { UnknownModuleException } from './errors/exceptions/unknown-module.exception';
1213
import { createContextId } from './helpers';
@@ -23,22 +24,19 @@ import { ContainerScanner } from './injector/container-scanner';
2324
import { Injector } from './injector/injector';
2425
import { InstanceWrapper } from './injector/instance-wrapper';
2526
import { Module } from './injector/module';
26-
import { ModuleTokenFactory } from './injector/module-token-factory';
27-
import { MESSAGES } from './constants';
2827

2928
/**
3029
* @publicApi
3130
*/
3231
export class NestApplicationContext implements INestApplicationContext {
33-
protected isInitialized: boolean = false;
32+
protected isInitialized = false;
3433
protected readonly injector = new Injector();
35-
private readonly moduleTokenFactory = new ModuleTokenFactory();
34+
private readonly activeShutdownSignals = new Array<string>();
3635
private readonly containerScanner: ContainerScanner;
37-
private readonly activeShutdownSignals: string[] = new Array<string>();
3836

3937
constructor(
4038
protected readonly container: NestContainer,
41-
private readonly scope: Type<any>[] = [],
39+
private readonly scope = new Array<Type<any>>(),
4240
private contextModule: Module = null,
4341
) {
4442
this.containerScanner = new ContainerScanner(container);
@@ -53,8 +51,9 @@ export class NestApplicationContext implements INestApplicationContext {
5351
const modules = this.container.getModules();
5452
const moduleMetatype = this.contextModule.metatype;
5553
const scope = this.scope.concat(moduleMetatype);
54+
const moduleTokenFactory = this.container.getModuleTokenFactory();
5655

57-
const token = this.moduleTokenFactory.create(module, scope);
56+
const token = moduleTokenFactory.create(module, scope);
5857
const selectedModule = modules.get(token);
5958
if (!selectedModule) {
6059
throw new UnknownModuleException();

0 commit comments

Comments
 (0)