import type { Container } from "../container/Container"; import type { ProviderToken } from "../container/types"; /** * AlveoApplication is the main class representing an Alveo application instance. * It provides methods to interact with the dependency injection container and manage the application lifecycle. */ export class AlveoApplication { constructor(private readonly container: Container) {} /** * Retrieves an instance of a provider from the application container. * * @param token The provider token (Class, String, or Symbol) * @returns A promise resolving to the instance of the provider */ public async get(token: ProviderToken): Promise { return this.container.get(token); } /** * Initializes the application by calling lifecycle hooks on all providers. * This is called automatically by AlveoFactory.create(). */ public async init(): Promise { await this.container.callLifecycleHook("onModuleInit"); await this.container.callLifecycleHook("onApplicationBootstrap"); return this; } /** * Gracefully shuts down the application by calling lifecycle hooks. * * @param signal The signal that triggered the shutdown */ public async close(signal?: string): Promise { await this.container.callLifecycleHook("onModuleDestroy", signal); await this.container.callLifecycleHook( "beforeApplicationShutdown", signal, ); await this.container.callLifecycleHook("onApplicationShutdown", signal); } }