feat: implement full lifecycle hooks

Adds onApplicationBootstrap, beforeApplicationShutdown, and onApplicationShutdown hooks with signal support.
This commit is contained in:
M1000fr
2026-01-11 17:20:14 +01:00
parent deb9e704fb
commit 0c166ab54c
4 changed files with 84 additions and 8 deletions

View File

@@ -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);
}
}