@@ -3,12 +3,12 @@ import { Type } from '@nestjs/common/interfaces/type.interface';
33import { isFunction , isNil , isString , isSymbol , isUndefined } from '@nestjs/common/utils/shared.utils' ;
44import { RuntimeException } from '../errors/exceptions/runtime.exception' ;
55import { UnknownExportException } from '../errors/exceptions/unknown-export.exception' ;
6+ import { GuardsConsumer } from '../guards/guards-consumer' ;
7+ import { GuardsContextCreator } from '../guards/guards-context-creator' ;
8+ import { ExternalContextCreator } from '../helpers/external-context-creator' ;
9+ import { InterceptorsConsumer } from '../interceptors/interceptors-consumer' ;
10+ import { InterceptorsContextCreator } from '../interceptors/interceptors-context-creator' ;
611import { Reflector } from '../services/reflector.service' ;
7- import { GuardsConsumer } from './../guards/guards-consumer' ;
8- import { GuardsContextCreator } from './../guards/guards-context-creator' ;
9- import { ExternalContextCreator } from './../helpers/external-context-creator' ;
10- import { InterceptorsConsumer } from './../interceptors/interceptors-consumer' ;
11- import { InterceptorsContextCreator } from './../interceptors/interceptors-context-creator' ;
1212import { InstanceWrapper , NestContainer } from './container' ;
1313import { ModuleRef } from './module-ref' ;
1414import { ModulesContainer } from './modules-container' ;
@@ -41,7 +41,7 @@ export class Module {
4141 constructor (
4242 private readonly _metatype : Type < any > ,
4343 private readonly _scope : Type < any > [ ] ,
44- container : NestContainer ,
44+ private readonly container : NestContainer ,
4545 ) {
4646 this . addCoreInjectables ( container ) ;
4747 }
@@ -92,7 +92,7 @@ export class Module {
9292 }
9393
9494 public addModuleRef ( ) {
95- const moduleRef = this . createModuleRefMetatype ( this . _components ) ;
95+ const moduleRef = this . createModuleRefMetatype ( ) ;
9696 this . _components . set ( ModuleRef . name , {
9797 name : ModuleRef . name ,
9898 metatype : ModuleRef as any ,
@@ -324,15 +324,24 @@ export class Module {
324324 } ) ;
325325 }
326326
327- public createModuleRefMetatype ( components ) {
328- return class {
329- public readonly components = components ;
330-
331- public get < T > ( type : OpaqueToken ) : T {
332- const name = isFunction ( type ) ? ( type as Type < any > ) . name : type ;
333- const exists = this . components . has ( name ) ;
327+ public createModuleRefMetatype ( ) : any {
328+ const self = this ;
329+ return class extends ModuleRef {
330+ constructor ( ) {
331+ super ( self . container ) ;
332+ }
334333
335- return exists ? ( this . components . get ( name ) . instance as T ) : null ;
334+ public get < TInput = any , TResult = TInput > (
335+ typeOrToken : Type < TInput > | string | symbol ,
336+ options : { strict : boolean } = { strict : true } ,
337+ ) : TResult {
338+ if ( ! ( options && options . strict ) ) {
339+ return this . find < TInput , TResult > ( typeOrToken ) ;
340+ }
341+ return this . findInstanceByPrototypeOrToken < TInput , TResult > (
342+ typeOrToken ,
343+ self ,
344+ ) ;
336345 }
337346 } ;
338347 }
0 commit comments