@analog-tools/inject
Version:
Dependency injection for AnalogJS server-side applications
45 lines (44 loc) • 1.81 kB
TypeScript
import { InjectionServiceClass } from './inject.types';
/**
* Service injection options
*/
export declare let _serviceRegistry: ServiceRegistry | null;
export declare function getServiceRegistry(): ServiceRegistry;
/**
* Service registry that provides access to all service singletons.
* Implements the singleton pattern for central service management.
*/
export declare class ServiceRegistry {
private serviceMap;
/**
* Register a service with a token
* @param token - The injection token for the service
* @param properties - The constructor parameters for the service class
*/
register<T>(token: InjectionServiceClass<T>, ...properties: ConstructorParameters<InjectionServiceClass<T>>): void;
registerAsUndefined<T>(token: InjectionServiceClass<T>): void;
registerCustomServiceInstance<T>(token: InjectionServiceClass<T>, customObject: Partial<T>): void;
/**
* Get a service by its token
* @param token - The injection token for the service
* @returns The requested service or undefined if not found
*/
getService<T>(token: InjectionServiceClass<T>): T | undefined;
/**
* Check if a service is registered
* @param token - The injection token for the service
* @returns True if the service is registered
*/
hasService<T>(token: InjectionServiceClass<T>): boolean;
/**
* Check if a service class is injectable
* @param token - The injection token for the service
* @returns True if the service has the INJECTABLE static property set to true
*/
isServiceInjectable<T>(token: InjectionServiceClass<T>): boolean;
getInjcectableName<T>(token: InjectionServiceClass<T>): string;
/**
* Clean up all services when the game is being destroyed
*/
destroy(): void;
}