@vizzly-testing/cli
Version:
Visual review platform for UI developers and designers
60 lines (59 loc) • 1.71 kB
TypeScript
/**
* Create a configured service container
* @param {Object} config - Configuration object
* @returns {ServiceContainer}
*/
export function createServiceContainer(config: any, command?: string): ServiceContainer;
/**
* @typedef {Object} ServiceDefinition
* @property {Function} factory - Factory function to create service instance
* @property {boolean} [singleton=true] - Whether to cache the instance
* @property {string[]} [dependencies=[]] - Array of dependency names
*/
/**
* Service container for dependency injection and lifecycle management
*/
export class ServiceContainer {
services: Map<any, any>;
instances: Map<any, any>;
starting: Map<any, any>;
/**
* Register a service
* @param {string} name - Service name
* @param {Function|ServiceDefinition} factoryOrDefinition - Factory function or service definition
*/
register(name: string, factoryOrDefinition: Function | ServiceDefinition): void;
/**
* Get a service instance
* @param {string} name - Service name
* @returns {Promise<any>} Service instance
*/
get(name: string): Promise<any>;
/**
* Start all registered services
*/
startAll(): Promise<void>;
/**
* Stop all services in reverse order
*/
stopAll(): Promise<void>;
/**
* Clear all services and instances
*/
clear(): void;
}
export const container: ServiceContainer;
export type ServiceDefinition = {
/**
* - Factory function to create service instance
*/
factory: Function;
/**
* - Whether to cache the instance
*/
singleton?: boolean;
/**
* - Array of dependency names
*/
dependencies?: string[];
};