@@ -19,6 +19,7 @@ import { RuntimeException } from '../errors/exceptions/runtime.exception';
1919import { UndefinedDependencyException } from '../errors/exceptions/undefined-dependency.exception' ;
2020import { UnknownDependenciesException } from '../errors/exceptions/unknown-dependencies.exception' ;
2121import { STATIC_CONTEXT } from './constants' ;
22+ import { INQUIRER } from './inquirer' ;
2223import {
2324 ContextId ,
2425 InstancePerContext ,
@@ -218,6 +219,7 @@ export class Injector {
218219 callback ,
219220 contextId ,
220221 wrapper ,
222+ inquirer ,
221223 ) ;
222224 }
223225
@@ -228,11 +230,17 @@ export class Injector {
228230 callback : ( args : any [ ] ) => void ,
229231 contextId = STATIC_CONTEXT ,
230232 inquirer ?: InstanceWrapper ,
233+ parentInquirer ?: InstanceWrapper ,
231234 ) {
232235 const inquirerId = this . getInquirerId ( inquirer ) ;
233236 const metadata = wrapper . getCtorMetadata ( ) ;
234237 if ( metadata && contextId !== STATIC_CONTEXT ) {
235- const deps = await this . loadCtorMetadata ( metadata , contextId , inquirer ) ;
238+ const deps = await this . loadCtorMetadata (
239+ metadata ,
240+ contextId ,
241+ inquirer ,
242+ parentInquirer ,
243+ ) ;
236244 return callback ( deps ) ;
237245 }
238246 const dependencies = isNil ( inject )
@@ -245,6 +253,9 @@ export class Injector {
245253 let isResolved = true ;
246254 const resolveParam = async ( param : unknown , index : number ) => {
247255 try {
256+ if ( this . isInquirer ( param , parentInquirer ) ) {
257+ return parentInquirer && parentInquirer . instance ;
258+ }
248259 const paramWrapper = await this . resolveSingleParam < T > (
249260 wrapper ,
250261 param ,
@@ -666,10 +677,16 @@ export class Injector {
666677 metadata : InstanceWrapper < any > [ ] ,
667678 contextId : ContextId ,
668679 inquirer ?: InstanceWrapper ,
680+ parentInquirer ?: InstanceWrapper ,
669681 ) : Promise < any [ ] > {
670682 const hosts = await Promise . all (
671683 metadata . map ( async item =>
672- this . resolveComponentHost ( item . host , item , contextId , inquirer ) ,
684+ this . resolveScopedComponentHost (
685+ item ,
686+ contextId ,
687+ inquirer ,
688+ parentInquirer ,
689+ ) ,
673690 ) ,
674691 ) ;
675692 const inquirerId = this . getInquirerId ( inquirer ) ;
@@ -705,4 +722,29 @@ export class Injector {
705722 private getInquirerId ( inquirer : InstanceWrapper | undefined ) : string {
706723 return inquirer && inquirer . id ;
707724 }
725+
726+ private resolveScopedComponentHost (
727+ item : InstanceWrapper ,
728+ contextId : ContextId ,
729+ inquirer ?: InstanceWrapper ,
730+ parentInquirer ?: InstanceWrapper ,
731+ ) {
732+ return this . isInquirerRequest ( item , parentInquirer )
733+ ? parentInquirer
734+ : this . resolveComponentHost ( item . host , item , contextId , inquirer ) ;
735+ }
736+
737+ private isInquirerRequest (
738+ item : InstanceWrapper ,
739+ parentInquirer : InstanceWrapper | undefined ,
740+ ) {
741+ return item . isTransient && item . name === INQUIRER && parentInquirer ;
742+ }
743+
744+ private isInquirer (
745+ param : unknown ,
746+ parentInquirer : InstanceWrapper | undefined ,
747+ ) {
748+ return param === INQUIRER && parentInquirer ;
749+ }
708750}
0 commit comments