UNPKG

codecrucible-synth

Version:

Production-Ready AI Development Platform with Multi-Voice Synthesis, Smithery MCP Integration, Enterprise Security, and Zero-Timeout Reliability

136 lines 4.5 kB
/** * Dependency Injection Container - Living Spiral Architecture Foundation * Resolves circular dependencies through interface abstraction and service registration * * Council Perspectives Applied: * - Architect: Clean separation of concerns with dependency inversion * - Maintainer: Easy service registration and lifecycle management * - Security Guardian: Controlled service access and initialization * - Performance Engineer: Lazy loading and singleton optimization * - Explorer: Extensible plugin architecture for new services */ import { EventEmitter } from 'events'; export type ServiceLifecycle = 'transient' | 'singleton' | 'scoped'; export type ServiceFactory<T = any> = (container: DependencyContainer) => T | Promise<T>; export interface ServiceOptions { lifecycle?: ServiceLifecycle; lazy?: boolean; dependencies?: string[]; metadata?: Record<string, any>; } export interface ServiceToken<T = any> { name: string; type?: new (...args: any[]) => T; } export declare class DependencyScope { private scopedInstances; private parent; constructor(parent: DependencyContainer); resolve<T>(token: string | ServiceToken<T>): T; dispose(): void; } /** * Dependency Injection Container Implementation * Provides service registration, resolution, and lifecycle management */ export declare class DependencyContainer extends EventEmitter { private services; private resolutionStack; private initializationOrder; private isDisposed; constructor(); /** * Register a service with the container */ register<T>(token: string | ServiceToken<T>, factory: ServiceFactory<T>, options?: ServiceOptions): void; /** * Register a class as a service with automatic dependency injection */ registerClass<T>(token: string | ServiceToken<T>, constructor: new (...args: any[]) => T, dependencies?: string[], options?: ServiceOptions): void; /** * Register a value as a singleton service */ registerValue<T>(token: string | ServiceToken<T>, value: T): void; /** * Resolve a service by token (synchronous) */ resolve<T>(token: string | ServiceToken<T>, context?: { scope?: DependencyScope; }): T; /** * Resolve a service asynchronously * ENHANCED: Properly handles async factories by using async resolution path */ resolveAsync<T>(token: string | ServiceToken<T>, context?: { scope?: DependencyScope; }): Promise<T>; /** * Create a new dependency scope */ createScope(): DependencyScope; /** * Check if a service is registered */ isRegistered(token: string | ServiceToken): boolean; /** * Get all registered service names */ getRegisteredServices(): string[]; /** * Get service registration metadata */ getServiceInfo(token: string | ServiceToken): ServiceOptions | null; /** * Initialize all eager services */ initializeEagerServices(): Promise<void>; /** * Dispose the container and all singleton instances */ dispose(): Promise<void>; /** * Resolve singleton service (synchronous - may return Promise for async factories) */ private resolveSingletonSync; /** * Resolve singleton service (async) */ private resolveSingleton; /** * Resolve transient service (synchronous) */ private resolveTransientSync; /** * Resolve transient service (async) */ private resolveTransient; /** * Create service instance using factory (synchronous - may return Promise) */ private createInstanceSync; /** * Create service instance using factory (async) * FIXED: Now properly handles async factory functions that return Promises */ private createInstance; /** * Validate service dependency graph for circular dependencies */ validateDependencyGraph(): { isValid: boolean; cycles: string[]; }; } /** * Global dependency container instance */ export declare const globalContainer: DependencyContainer; /** * Service token factory for type-safe registration */ export declare function createServiceToken<T>(name: string): ServiceToken<T>; /** * Decorator for automatic service registration */ export declare function Injectable(token: string, options?: ServiceOptions): <T extends new (...args: any[]) => any>(constructor: T) => T; //# sourceMappingURL=dependency-container.d.ts.map