feat: implement full lifecycle hooks
Adds onApplicationBootstrap, beforeApplicationShutdown, and onApplicationShutdown hooks with signal support.
This commit is contained in:
@@ -19,18 +19,26 @@ export class AlveoApplication {
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the application by calling onModuleInit hooks on all providers.
|
||||
* Initializes the application by calling lifecycle hooks on all providers.
|
||||
* This is called automatically by AlveoFactory.create().
|
||||
*/
|
||||
public async init(): Promise<this> {
|
||||
await this.container.callLifecycleHook("onModuleInit");
|
||||
await this.container.callLifecycleHook("onApplicationBootstrap");
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gracefully shuts down the application by calling onModuleDestroy hooks.
|
||||
* Gracefully shuts down the application by calling lifecycle hooks.
|
||||
*
|
||||
* @param signal The signal that triggered the shutdown
|
||||
*/
|
||||
public async close(): Promise<void> {
|
||||
await this.container.callLifecycleHook("onModuleDestroy");
|
||||
public async close(signal?: string): Promise<void> {
|
||||
await this.container.callLifecycleHook("onModuleDestroy", signal);
|
||||
await this.container.callLifecycleHook(
|
||||
"beforeApplicationShutdown",
|
||||
signal,
|
||||
);
|
||||
await this.container.callLifecycleHook("onApplicationShutdown", signal);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user