andy-stack_vaultkeeper-ai/Services/DependencyService.ts
Andrew Beal c69351404b Add ability for users to provide suggestions during diff review through new DiffControls component. Integrate suggestion workflow into chat input, allowing users to approve/reject changes or provide feedback without interrupting the review process.
Improve component lifecycle management by converting DiffService and StatusBarService to extend Component class, ensuring proper cleanup and event handling. Add automatic service cleanup in DependencyService during deregistration.

Refine error handling in AI function responses to return error messages instead of Error objects for better serialization. Update user rejection messaging to provide clearer guidance to AI about stopping actions.
2025-11-27 12:39:08 +00:00

36 lines
No EOL
1,005 B
TypeScript

import { Exception } from "Helpers/Exception";
import type { Component } from "obsidian";
const services = new Map<symbol, unknown>();
export function RegisterSingleton<T>(type: symbol, instance: T) {
services.set(type, instance);
}
export function RegisterTransient<T>(type: symbol, factory: () => T) {
services.set(type, factory);
}
export function Resolve<T>(type: symbol): T {
const service = services.get(type);
if (!service) {
Exception.throw(`Service not found for type: ${type.description}`);
}
if (typeof service === "function") {
// It"s a transient factory, return a new instance
return (service as () => T)();
}
// It"s a singleton, return the existing instance
return service as T;
}
export function DeregisterAllServices() {
services.forEach((service) => {
if (service && typeof service === "object" && "unload" in service) {
(service as Component).unload();
}
});
services.clear();
}