feat: implement full lifecycle hooks
Adds onApplicationBootstrap, beforeApplicationShutdown, and onApplicationShutdown hooks with signal support.
This commit is contained in:
@@ -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",
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user