42 lines
955 B
TypeScript
42 lines
955 B
TypeScript
/**
|
|
* 服务容器接口
|
|
* 负责管理和提供所有系统服务的实例
|
|
*/
|
|
export interface IServiceContainer {
|
|
/**
|
|
* 注册服务
|
|
* @param id 服务唯一标识符
|
|
* @param factory 服务工厂函数
|
|
* @param dependencies 依赖的服务ID数组
|
|
*/
|
|
register<T>(id: string, factory: ServiceFactory<T>, dependencies?: string[]): void
|
|
|
|
/**
|
|
* 获取服务实例
|
|
* @param id 服务唯一标识符
|
|
* @returns 服务实例
|
|
* @throws 当服务未注册时抛出错误
|
|
*/
|
|
getService<T>(id: string): T
|
|
|
|
/**
|
|
* 检查服务是否已注册
|
|
* @param id 服务唯一标识符
|
|
* @returns 是否已注册
|
|
*/
|
|
has(id: string): boolean
|
|
|
|
/**
|
|
* 初始化所有服务
|
|
* 按照依赖关系顺序初始化服务
|
|
*/
|
|
initialize(): void
|
|
}
|
|
|
|
/**
|
|
* 服务工厂函数类型
|
|
* @param container 服务容器实例
|
|
* @returns 服务实例
|
|
*/
|
|
export type ServiceFactory<T> = (container: IServiceContainer) => T
|