@analog-tools/inject
Version:
Dependency injection for AnalogJS server-side applications
36 lines (35 loc) • 1.33 kB
TypeScript
import { InjectionServiceClass, InjectOptions } from './inject.types';
/**
* Custom error class for injection-related errors
*/
export declare class InjectionError extends Error {
readonly token?: string | undefined;
readonly cause?: Error | undefined;
constructor(message: string, token?: string | undefined, cause?: Error | undefined);
}
/**
* Error for circular dependency detection
*/
export declare class CircularDependencyError extends InjectionError {
constructor(dependencyChain: string[]);
}
/**
* Type-safe inject function with strict null checking
*/
export declare function inject<T>(token: InjectionServiceClass<T>, options?: InjectOptions): T;
/**
* Type-safe service registration with strict typing
*/
export declare function registerService<T, Args extends any[] = any[]>(token: InjectionServiceClass<T, Args>, ...properties: Args): void;
/**
* Register a service as undefined for testing
*/
export declare function registerServiceAsUndefined<T>(token: InjectionServiceClass<T>): void;
/**
* Check if a service is available without throwing
*/
export declare function hasService<T>(token: InjectionServiceClass<T>): boolean;
/**
* Try to inject a service, returning undefined if not available
*/
export declare function tryInject<T>(token: InjectionServiceClass<T>): T | undefined;