import { ServiceId, ServiceLifecycle, ServiceContract, ServiceRegistrationOptions, ServiceFactory, DependencyContainer } from './types'; /** * Implementation of the dependency injection container. * * @example * ```typescript * // Define a service contract * const LoggerContract = createServiceContract('logger'); * * // Create container and register * const container = new DependencyInjectorImpl(); * container.register(LoggerContract, new ConsoleLogger()); * * // Resolve service * const logger = container.resolve(LoggerContract); * logger.info('Hello, world!'); * ``` * * @example With factories * ```typescript * // Register a factory * container.register( * DatabaseContract, * (c) => new Database(c.resolve(ConfigContract)), * { scope: 'singleton', lifecycle: 'bootstrap' } * ); * ``` */ export declare class DependencyInjectorImpl implements DependencyContainer { /** Service registry */ private readonly services; /** Parent container for hierarchical resolution */ private readonly parent; /** Resolution counter for ordering */ private resolutionCounter; /** Disposed flag */ private disposed; /** * Creates a new dependency injector. * @param parent - Optional parent container */ constructor(parent?: DependencyInjectorImpl | null); /** * Registers a service implementation. * @template T - Service type * @param contract - Service contract * @param implementation - Implementation or factory * @param options - Registration options */ register(contract: ServiceContract, implementation: T | ServiceFactory, options?: ServiceRegistrationOptions): void; /** * Registers a factory function. * @template T - Service type * @param contract - Service contract * @param factory - Factory function * @param options - Registration options */ registerFactory(contract: ServiceContract, factory: ServiceFactory, options?: ServiceRegistrationOptions): void; /** * Resolves a service. * @template T - Service type * @param contract - Service contract * @returns Resolved service instance * @throws Error if service not found or circular dependency detected */ resolve(contract: ServiceContract): T; /** * Tries to resolve a service, returning undefined if not found. * @template T - Service type * @param contract - Service contract * @returns Resolved service or undefined */ tryResolve(contract: ServiceContract): T | undefined; /** * Checks if a service is registered. * @param contract - Service contract * @returns True if registered */ has(contract: ServiceContract): boolean; /** * Checks if a service ID is registered. * @param id - Service ID * @returns True if registered */ hasById(id: ServiceId): boolean; /** * Unregisters a service. * @param contract - Service contract * @returns True if service was unregistered */ unregister(contract: ServiceContract): boolean; /** * Gets all services with a specific tag. * @template T - Service type * @param tag - Tag to search for * @returns Array of matching services */ getByTag(tag: string): T[]; /** * Gets all registered service contracts. * @returns Array of service contracts */ getRegisteredContracts(): ServiceContract[]; /** * Gets services by lifecycle phase. * @param lifecycle - Lifecycle phase * @returns Array of service contracts */ getByLifecycle(lifecycle: ServiceLifecycle): ServiceContract[]; /** * Creates a child container. * @returns Child container */ createChild(): DependencyContainer; /** * Creates a scoped container for request-scoped services. * @returns Scoped container */ createScope(): DependencyContainer; /** * Initializes all services in lifecycle order. * @returns Promise that resolves when all services are initialized */ initializeAll(): Promise; /** * Disposes the container and all disposable services. */ dispose(): Promise; /** * Ensures container is not disposed. */ private ensureNotDisposed; /** * Resolves a service with context. * @template T - Service type * @param contract - Service contract * @param context - Resolution context * @returns Resolved service */ private resolveWithContext; /** * Resolves a service entry. * @template T - Service type * @param entry - Service entry * @param context - Resolution context * @returns Resolved service */ private resolveEntry; /** * Resolves a service entry asynchronously. * @template T - Service type * @param entry - Service entry * @param context - Resolution context * @returns Promise resolving to service */ private resolveEntryAsync; } /** * Creates a typed service contract. * @template T - Service interface type * @param name - Service name * @param defaultValue - Optional default implementation * @param lifecycle - Service lifecycle phase * @returns Service contract * * @example * ```typescript * interface Logger { * info(message: string): void; * error(message: string, error?: Error): void; * } * * const LoggerContract = createServiceContract('logger', { * info: (msg) => console.log(msg), * error: (msg, err) => console.error(msg, err), * }); * ``` */ export declare function createServiceContract(name: string, defaultValue?: T, lifecycle?: ServiceLifecycle): ServiceContract; /** * Gets the global dependency container. * @returns Global container instance */ export declare function getGlobalContainer(): DependencyInjectorImpl; /** * Sets the global dependency container. * @param container - Container instance */ export declare function setGlobalContainer(container: DependencyInjectorImpl): void; /** * Resets the global dependency container. */ export declare function resetGlobalContainer(): void; /** * Registers a service in the global container. */ export declare function registerService(contract: ServiceContract, implementation: T | ServiceFactory, options?: ServiceRegistrationOptions): void; /** * Resolves a service from the global container. */ export declare function resolveService(contract: ServiceContract): T; /** * Tries to resolve a service from the global container. */ export declare function tryResolveService(contract: ServiceContract): T | undefined; /** * Logger service contract. */ export interface ILogger { debug(message: string, data?: unknown): void; info(message: string, data?: unknown): void; warn(message: string, data?: unknown): void; error(message: string, error?: Error, data?: unknown): void; } export declare const LoggerContract: ServiceContract; /** * Configuration service contract. */ export interface IConfigService { get(key: string): T | undefined; set(key: string, value: T): void; has(key: string): boolean; getAll(): Record; } export declare const ConfigContract: ServiceContract; /** * Telemetry service contract. */ export interface ITelemetryService { trackEvent(name: string, properties?: Record): void; trackMetric(name: string, value: number, properties?: Record): void; trackException(error: Error, properties?: Record): void; flush(): Promise; } export declare const TelemetryContract: ServiceContract;