import { StateValue } from './state-value'; export type Injectable = T | (new (...args: any[]) => T); export type InjectableKey = string | (new (...args: any[]) => T) | (abstract new (...args: any[]) => T); declare enum RegistrationType { CLASS = "class", INSTANCE = "instance", FACTORY = "factory" } interface Registration { type: RegistrationType; value: T | (new () => T) | (() => T); } export declare class DependencyContainer { protected dependencies: Map>; protected instances: Map; protected states: Map>; protected parent?: DependencyContainer; constructor(parent?: DependencyContainer); /** * Get the string key for an injectable * @param injectable The injectable key (string or class type) * @returns The string key */ getInjectableKey(injectable: InjectableKey): string; /** * Register a class dependency (instantiated lazily, cached as singleton). * If implementation is not provided, uses the key as the implementation. * @param key The injectable key (string or class type) * @param implementation Optional class implementation (defaults to key) */ register(key: InjectableKey, implementation?: T | (new () => T)): void; /** * Register a pre-instantiated singleton dependency. * @param key The injectable key (string or class type) * @param instance The instance to register */ registerInstance(key: InjectableKey, instance: T): void; /** * Register a factory function that creates a new instance each time. * @param key The injectable key (string or class type) * @param factory The factory function */ registerFactory(key: InjectableKey, factory: () => T): void; /** * Get a dependency, searching up the parent chain if not found * @param injectable The key of the dependency to retrieve * @returns The dependency value, or undefined if not found */ get(injectable: InjectableKey): T | undefined; /** * Get a dependency, throwing an error if not found * @param injectable The dependency key to retrieve * @returns The dependency value */ require(injectable: InjectableKey): T; /** * Check if a dependency exists in the container or its parents * @param injectable The injectable to check */ has(injectable: InjectableKey): boolean; /** * Register a stateful value in the container. * @param key The state key (string or class type) * @param initialValue The initial value for the state * @returns The StateValue wrapper */ registerState(key: InjectableKey, initialValue: T): StateValue; /** * Get a state value, searching up the parent chain if not found. * @param key The state key (string or class type) * @returns The StateValue wrapper * @throws Error if state is not found */ getState(key: InjectableKey): StateValue; /** * Check if a state exists in the container or its parents. * @param key The state key (string or class type) */ hasState(key: InjectableKey): boolean; /** * Subscribe to state changes. * @param key The state key (string or class type) * @param callback Function to call when state changes, * receives (newValue, oldValue) * @returns An unsubscribe function */ subscribe(key: InjectableKey, callback: (newValue: T, oldValue: T) => void): () => void; /** * Subscribe to multiple state changes with a single callback. * @param keys The state keys to subscribe to * @param callback Function to call when any subscribed state changes, * receives all current state values as arguments * @returns An unsubscribe function that removes all subscriptions */ subscribeMany(keys: InjectableKey[], callback: (...values: unknown[]) => void): () => void; /** * Create a child container that inherits from this one. * Child containers have independent state registrations. */ extend(): DependencyContainer; /** * Set the parent container * @internal */ setParent(parent: DependencyContainer): void; /** * Resolve dependencies for classes that implement HasDependencies * @param instances Optional array of instances to inject. If not * provided, injects all registered dependencies in this container. */ inject(instances?: any[]): void; /** * Get all available registration keys from this container and parents */ private getAvailableKeys; protected isConstructor(value: unknown): boolean; } export {};