refactor(core): remove ManagerRegistry singleton, use instance-based DI
Replace static getInstance() pattern with public constructor to enable multiple independent BimEngine instances on the same page. BaseManager and BaseDialogManager now accept registry via constructor parameter. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* Manager 注册表
|
||||
* 全局单例,提供所有 Manager 的集中访问点
|
||||
* 每个 BimEngine 实例持有独立的 Registry,实现多实例隔离
|
||||
*/
|
||||
import { EventEmitter } from './event-emitter';
|
||||
import type { EngineEvents } from '../types/events';
|
||||
@@ -24,12 +24,10 @@ import type { ComponentDetailManager } from '../managers/component-detail-manage
|
||||
import type { AiChatManager } from '../managers/ai-chat-manager';
|
||||
|
||||
/**
|
||||
* Manager 注册表 - 单例模式
|
||||
* 提供所有 Manager 的全局访问点,替代 engine 层层传递
|
||||
* Manager 注册表 - 实例模式
|
||||
* 每个 BimEngine 创建独立的 Registry 实例,替代旧的全局单例
|
||||
*/
|
||||
export class ManagerRegistry {
|
||||
/** 单例实例 */
|
||||
private static instance: ManagerRegistry | null = null;
|
||||
/** 事件发射器 */
|
||||
private eventEmitter: EventEmitter = new EventEmitter();
|
||||
|
||||
@@ -72,22 +70,29 @@ export class ManagerRegistry {
|
||||
/** AI 聊天管理器 */
|
||||
public aiChat: AiChatManager | null = null;
|
||||
|
||||
private constructor() {}
|
||||
constructor() {}
|
||||
|
||||
/** 获取单例实例 */
|
||||
public static getInstance(): ManagerRegistry {
|
||||
if (!ManagerRegistry.instance) {
|
||||
ManagerRegistry.instance = new ManagerRegistry();
|
||||
}
|
||||
return ManagerRegistry.instance;
|
||||
}
|
||||
|
||||
/** 重置单例(用于测试或重新初始化) */
|
||||
public static reset(): void {
|
||||
if (ManagerRegistry.instance) {
|
||||
ManagerRegistry.instance.eventEmitter.clear();
|
||||
ManagerRegistry.instance = null;
|
||||
}
|
||||
/** 重置(清理事件和引用) */
|
||||
public reset(): void {
|
||||
this.eventEmitter.clear();
|
||||
this.container = null;
|
||||
this.wrapper = null;
|
||||
this.toolbar = null;
|
||||
this.dialog = null;
|
||||
this.engine3d = null;
|
||||
this.buttonGroup = null;
|
||||
this.rightKey = null;
|
||||
this.constructTree = null;
|
||||
this.measure = null;
|
||||
this.walkControl = null;
|
||||
this.sectionPlane = null;
|
||||
this.sectionAxis = null;
|
||||
this.sectionBox = null;
|
||||
this.walkPath = null;
|
||||
this.walkPlanView = null;
|
||||
this.engineInfo = null;
|
||||
this.componentDetail = null;
|
||||
this.aiChat = null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user