mirror of
https://github.com/andy-stack/vaultkeeper-ai.git
synced 2026-07-22 16:30:27 +00:00
Add DeregisterAllServices() calls in afterEach hooks across all test files to clear singleton registry between tests. Export DeregisterAllServices from DependencyService. Fix StatusBarService test timing issues with animation frames.
28 lines
No EOL
739 B
TypeScript
28 lines
No EOL
739 B
TypeScript
const services = new Map<symbol, any>();
|
|
|
|
export function RegisterSingleton<T>(type: symbol, instance: T): void {
|
|
services.set(type, instance);
|
|
}
|
|
|
|
export function RegisterTransient<T>(type: symbol, factory: () => T): void {
|
|
services.set(type, factory);
|
|
}
|
|
|
|
export function Resolve<T>(type: symbol): T {
|
|
const service = services.get(type);
|
|
if (!service) {
|
|
throw new Error(`Service not found for type: ${type.description}`);
|
|
}
|
|
|
|
if (typeof service === 'function') {
|
|
// It's a transient factory, return a new instance
|
|
return service();
|
|
}
|
|
|
|
// It's a singleton, return the existing instance
|
|
return service as T;
|
|
}
|
|
|
|
export function DeregisterAllServices(): void {
|
|
services.clear();
|
|
} |