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

@@ -373,4 +373,44 @@ describe("Alveo Container & DI", () => {
expect(service.config).toBe("async_dynamic_config");
});
test("should call all lifecycle hooks in the correct order", async () => {
const callOrder: string[] = [];
@Injectable()
class FullLifecycleService {
async onModuleInit() {
callOrder.push("onModuleInit");
}
async onApplicationBootstrap() {
callOrder.push("onApplicationBootstrap");
}
async onModuleDestroy() {
callOrder.push("onModuleDestroy");
}
async beforeApplicationShutdown(signal?: string) {
callOrder.push(`beforeApplicationShutdown:${signal}`);
}
async onApplicationShutdown(signal?: string) {
callOrder.push(`onApplicationShutdown:${signal}`);
}
}
@Module({
providers: [FullLifecycleService],
})
class RootModule {}
const app = await AlveoFactory.create(RootModule);
expect(callOrder).toEqual(["onModuleInit", "onApplicationBootstrap"]);
await app.close("SIGTERM");
expect(callOrder).toEqual([
"onModuleInit",
"onApplicationBootstrap",
"onModuleDestroy",
"beforeApplicationShutdown:SIGTERM",
"onApplicationShutdown:SIGTERM",
]);
});
});