/** * Contract for service providers that hook into the application lifecycle. * Implement `register` to bind services, `boot` to run after all providers are registered, * and `shutdown` to clean up resources on application teardown. */ export interface ServiceProvider { register?(app: App): void | Promise; boot?(app: App): void | Promise; shutdown?(app: App): void | Promise; } /** * Application container that manages service bindings, singletons, and provider lifecycle. * * @example * const app = createApp() * app.singleton('db', () => new Database(config)) * app.register(new AuthProvider()) * await app.boot() * const db = app.use('db') */ export declare class App { private services; private providers; private _booted; /** * Register a transient service factory. A new instance is created on every `use()` call. * @param name - Unique service identifier * @param factory - Factory function that creates the service instance * @returns The app instance for chaining */ bind(name: string, factory: () => T): this; /** * Register a singleton service factory. The instance is created once on first `use()` call and cached. * @param name - Unique service identifier * @param factory - Factory function that creates the service instance * @returns The app instance for chaining */ singleton(name: string, factory: () => T): this; /** * Register a pre-created instance directly into the container. * @param name - Unique service identifier * @param value - The instance to store * @returns The app instance for chaining */ instance(name: string, value: any): this; /** * Resolve a service from the container by name. Throws if the service is not registered. * * Security: `name` is a trusted service identifier. NEVER pass a * user-controlled value (e.g. `ctx.input('service')`) here — doing so lets a * request resolve an arbitrary registered service (db, mailer) and is an * IDOR / service-abuse footgun. Keep an explicit allow-list at the call site * if a name must ever derive from input. * * @param name - The service identifier to resolve * @returns The resolved service instance * @throws {Error} If the service is not registered */ use(name: string): T; /** * Check whether a service is registered in the container. * @param name - The service identifier to check * @returns True if the service exists */ has(name: string): boolean; /** * Register a single service provider. * @param provider - The service provider instance to register * @returns The app instance for chaining */ register(provider: ServiceProvider): this; /** * Register multiple service providers at once. Accepts both instances and constructor classes. * @param providers - Array of provider instances or provider constructors * @returns The app instance for chaining */ registerAll(providers: (ServiceProvider | (new () => ServiceProvider))[]): this; /** * Returns every registered provider instance. Used by `tekir()` to * collect provider-exposed CLI commands (`Provider.commands`). */ getProviders(): ServiceProvider[]; /** * Boot all registered providers in two phases: register, then boot. * Safe to call multiple times; subsequent calls are no-ops. * @returns A promise that resolves when all providers have booted */ boot(): Promise; /** * Gracefully shut down all providers in reverse registration order. * @returns A promise that resolves when all providers have been shut down */ shutdown(): Promise; get booted(): boolean; } /** * Create and return a new global App instance. * @returns A fresh App container */ export declare function createApp(): App;