import { type interfaces, LazyServiceIdentifier } from 'inversify'; export type Newable = interfaces.Newable; export type ServiceIdentifier = interfaces.ServiceIdentifier; export type FactoryFunction = () => interfaces.ServiceIdentifier; export type ServiceDescriptor = T | LazyServiceIdentifier | FactoryFunction; export { LazyServiceIdentifier }; export interface ServicesAccessor { get(id: ServiceIdentifier): T; } const _registry: [ServiceIdentifier, ServiceDescriptor][] = []; export function registerSingleton(id: ServiceIdentifier, useValue: T | LazyServiceIdentifier): void; export function registerSingleton(id: ServiceIdentifier, useFactory: FactoryFunction): void; export function registerSingleton( id: ServiceIdentifier, useClass: Newable, supportsDelayedInstantiation: true, ): void; export function registerSingleton( id: ServiceIdentifier, ctorOrDescriptor: T | LazyServiceIdentifier | Newable | FactoryFunction, supportsDelayedInstantiation?: boolean, ): void { if (ctorOrDescriptor instanceof LazyServiceIdentifier) { _registry.push([id, ctorOrDescriptor]); return; } if (typeof ctorOrDescriptor === 'function' && supportsDelayedInstantiation) { _registry.push([id, new LazyServiceIdentifier(() => ctorOrDescriptor as Newable)]); return; } _registry.push([id, ctorOrDescriptor]); } export function getSingletonServiceDescriptors(): [ServiceIdentifier, ServiceDescriptor][] { return _registry; }