mirror of
https://github.com/nestjs/nest.git
synced 2026-02-21 23:11:44 +00:00
fix(core): fix app.select method (share token factory)
This commit is contained in:
@@ -8,7 +8,7 @@ export interface ModuleFactory {
|
||||
}
|
||||
|
||||
export class ModuleCompiler {
|
||||
private readonly moduleTokenFactory = new ModuleTokenFactory();
|
||||
constructor(private readonly moduleTokenFactory = new ModuleTokenFactory()) {}
|
||||
|
||||
public async compile(
|
||||
metatype: Type<any> | DynamicModule | Promise<DynamicModule>,
|
||||
|
||||
@@ -12,11 +12,13 @@ import { ModuleCompiler } from './compiler';
|
||||
import { InternalCoreModule } from './internal-core-module';
|
||||
import { InternalProvidersStorage } from './internal-providers-storage';
|
||||
import { Module } from './module';
|
||||
import { ModuleTokenFactory } from './module-token-factory';
|
||||
import { ModulesContainer } from './modules-container';
|
||||
|
||||
export class NestContainer {
|
||||
private readonly globalModules = new Set<Module>();
|
||||
private readonly moduleCompiler = new ModuleCompiler();
|
||||
private readonly moduleTokenFactory = new ModuleTokenFactory();
|
||||
private readonly moduleCompiler = new ModuleCompiler(this.moduleTokenFactory);
|
||||
private readonly modules = new ModulesContainer();
|
||||
private readonly dynamicModulesMetadata = new Map<
|
||||
string,
|
||||
@@ -115,8 +117,9 @@ export class NestContainer {
|
||||
relatedModule: Type<any> | DynamicModule,
|
||||
token: string,
|
||||
) {
|
||||
if (!this.modules.has(token)) return;
|
||||
|
||||
if (!this.modules.has(token)) {
|
||||
return;
|
||||
}
|
||||
const module = this.modules.get(token);
|
||||
const parent = module.metatype;
|
||||
|
||||
@@ -222,4 +225,8 @@ export class NestContainer {
|
||||
this.internalCoreModule = moduleRef;
|
||||
this.modules[InternalCoreModule.name] = moduleRef;
|
||||
}
|
||||
|
||||
public getModuleTokenFactory(): ModuleTokenFactory {
|
||||
return this.moduleTokenFactory;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
import {
|
||||
INestApplicationContext,
|
||||
Logger,
|
||||
LoggerService,
|
||||
ShutdownSignal,
|
||||
} from '@nestjs/common';
|
||||
import { Logger } from '@nestjs/common';
|
||||
import { Abstract } from '@nestjs/common/interfaces';
|
||||
import { Type } from '@nestjs/common/interfaces/type.interface';
|
||||
import { isEmpty } from '@nestjs/common/utils/shared.utils';
|
||||
import { MESSAGES } from './constants';
|
||||
import { UnknownElementException } from './errors/exceptions/unknown-element.exception';
|
||||
import { UnknownModuleException } from './errors/exceptions/unknown-module.exception';
|
||||
import { createContextId } from './helpers';
|
||||
@@ -23,22 +24,19 @@ import { ContainerScanner } from './injector/container-scanner';
|
||||
import { Injector } from './injector/injector';
|
||||
import { InstanceWrapper } from './injector/instance-wrapper';
|
||||
import { Module } from './injector/module';
|
||||
import { ModuleTokenFactory } from './injector/module-token-factory';
|
||||
import { MESSAGES } from './constants';
|
||||
|
||||
/**
|
||||
* @publicApi
|
||||
*/
|
||||
export class NestApplicationContext implements INestApplicationContext {
|
||||
protected isInitialized: boolean = false;
|
||||
protected isInitialized = false;
|
||||
protected readonly injector = new Injector();
|
||||
private readonly moduleTokenFactory = new ModuleTokenFactory();
|
||||
private readonly activeShutdownSignals = new Array<string>();
|
||||
private readonly containerScanner: ContainerScanner;
|
||||
private readonly activeShutdownSignals: string[] = new Array<string>();
|
||||
|
||||
constructor(
|
||||
protected readonly container: NestContainer,
|
||||
private readonly scope: Type<any>[] = [],
|
||||
private readonly scope = new Array<Type<any>>(),
|
||||
private contextModule: Module = null,
|
||||
) {
|
||||
this.containerScanner = new ContainerScanner(container);
|
||||
@@ -53,8 +51,9 @@ export class NestApplicationContext implements INestApplicationContext {
|
||||
const modules = this.container.getModules();
|
||||
const moduleMetatype = this.contextModule.metatype;
|
||||
const scope = this.scope.concat(moduleMetatype);
|
||||
const moduleTokenFactory = this.container.getModuleTokenFactory();
|
||||
|
||||
const token = this.moduleTokenFactory.create(module, scope);
|
||||
const token = moduleTokenFactory.create(module, scope);
|
||||
const selectedModule = modules.get(token);
|
||||
if (!selectedModule) {
|
||||
throw new UnknownModuleException();
|
||||
|
||||
Reference in New Issue
Block a user