mirror of
https://github.com/nestjs/nest.git
synced 2026-02-21 23:11:44 +00:00
feat(@nestjs/core): Add init function on NestApplicationContext to API
This commit is contained in:
@@ -29,4 +29,12 @@ export interface INestApplicationContext {
|
||||
* @returns {void}
|
||||
*/
|
||||
useLogger(logger: LoggerService);
|
||||
|
||||
/**
|
||||
* Initalizes the Nest application.
|
||||
* Calls the Nest lifecycle events.
|
||||
*
|
||||
* @returns {Promise<this>} The NestApplicationContext instance as Promise
|
||||
*/
|
||||
init(): Promise<this>;
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import { ModuleTokenFactory } from './injector/module-token-factory';
|
||||
export class NestApplicationContext implements INestApplicationContext {
|
||||
private readonly moduleTokenFactory = new ModuleTokenFactory();
|
||||
private readonly containerScanner: ContainerScanner;
|
||||
protected isInitialized: boolean = false;
|
||||
|
||||
constructor(
|
||||
protected readonly container: NestContainer,
|
||||
@@ -59,9 +60,20 @@ export class NestApplicationContext implements INestApplicationContext {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initalizes the Nest application.
|
||||
* Calls the Nest lifecycle events.
|
||||
*
|
||||
* @returns {Promise<this>} The NestApplicationContext instance as Promise
|
||||
*/
|
||||
public async init(): Promise<this> {
|
||||
// Ignore if is already initialized
|
||||
if (this.isInitialized) return;
|
||||
|
||||
await this.callInitHook();
|
||||
await this.callBootstrapHook();
|
||||
|
||||
this.isInitialized = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@@ -59,7 +59,6 @@ export class NestApplication extends NestApplicationContext
|
||||
private readonly routesResolver: Resolver;
|
||||
private readonly microservices = [];
|
||||
private httpServer: http.Server;
|
||||
private isInitialized = false;
|
||||
|
||||
constructor(
|
||||
container: NestContainer,
|
||||
|
||||
@@ -32,7 +32,6 @@ export class NestMicroservice extends NestApplicationContext
|
||||
private microserviceConfig: MicroserviceOptions;
|
||||
private server: Server & CustomTransportStrategy;
|
||||
private isTerminated = false;
|
||||
private isInitialized = false;
|
||||
private isInitHookCalled = false;
|
||||
|
||||
constructor(
|
||||
|
||||
Reference in New Issue
Block a user