@@ -10,9 +10,10 @@ import { NestApplication } from './nest-application';
1010import { isFunction } from '@nestjs/common/utils/shared.utils' ;
1111import { MicroserviceConfiguration } from '@nestjs/common/interfaces/microservices/microservice-configuration.interface' ;
1212import { ExpressAdapter } from './adapters/express-adapter' ;
13- import { INestApplication , INestMicroservice } from '@nestjs/common' ;
13+ import { INestApplication , INestMicroservice , INestApplicationContext } from '@nestjs/common' ;
1414import { MetadataScanner } from './metadata-scanner' ;
1515import { MicroservicesPackageNotFoundException } from './errors/exceptions/microservices-package-not-found.exception' ;
16+ import { NestApplicationContext } from './nest-application-context' ;
1617
1718const { NestMicroservice } = optional ( '@nestjs/microservices/nest-microservice' ) || { } as any ;
1819
@@ -27,7 +28,7 @@ export class NestFactoryStatic {
2728 /**
2829 * Creates an instance of the NestApplication (returns Promise)
2930 *
30- * @param { } module Entry ApplicationModule class
31+ * @param { } module Entry (root) application module class
3132 * @param { } express Optional express() server instance
3233 * @returns an `Promise` of the INestApplication instance
3334 */
@@ -41,7 +42,7 @@ export class NestFactoryStatic {
4142 /**
4243 * Creates an instance of the NestMicroservice (returns Promise)
4344 *
44- * @param { } module Entry ApplicationModule class
45+ * @param { } module Entry (root) application module class
4546 * @param {MicroserviceConfiguration } config Optional microservice configuration
4647 * @returns an `Promise` of the INestMicroservice instance
4748 */
@@ -59,6 +60,22 @@ export class NestFactoryStatic {
5960 ) ;
6061 }
6162
63+ /**
64+ * Creates an instance of the NestApplicationContext (returns Promise)
65+ *
66+ * @param { } module Entry (root) application module class
67+ * @returns an `Promise` of the INestApplicationContext instance
68+ */
69+ public async createApplicationContext ( module ) : Promise < INestApplicationContext > {
70+ await this . initialize ( module ) ;
71+
72+ const modules = this . container . getModules ( ) . values ( ) ;
73+ const root = modules . next ( ) . value ;
74+ return this . createNestInstance < INestApplicationContext > (
75+ new NestApplicationContext ( this . container , [ ] , root ) ,
76+ ) ;
77+ }
78+
6279 private createNestInstance < T > ( instance : T ) {
6380 return this . createProxy ( instance ) ;
6481 }
0 commit comments