In-memory IServiceRegistry with registration recording.
Reproduces the kernel ServiceRegistry's observable semantics
field-for-field, because a double that diverges hides the bug it
exists to catch:
getresolves a factory once and caches it; on a miss throws the kernel's verbatim two-sentence message.getAllreturns[...(single ? [single] : []), ...multi]— the single registration is included, not just the multi list.register/registerFactoryhonorRegisterOptionsexactly:multi: trueappends; otherwise a second registration throws unlessoverride: truereplaces it.haschecks both maps;unregisterdeletes from both.- A readonly
registrationsfield records every call.
registrations: ReadonlyArray<{ token: string; multi: boolean; }>
Records every register/registerFactory call, in order.
Exposed as a ReadonlyArray so a test can assert against the recording
without being able to rewrite it; #record is the mutable backing store.
get<T extends object>(token: CapabilityToken): T
Resolves a service by capability token.
On a multi-provider token this returns the FIRST registered provider; use
IServiceRegistry.getAll to reach all of them.
getAll<T extends object>(token: CapabilityToken): readonly T[]
Resolves every provider registered for a multi-provider token.
has(token: CapabilityToken): boolean
Reports whether a capability is available.
register<T extends object>(token: CapabilityToken,service: T,options?: RegisterOptions): void
Registers a service instance under a capability token.
registerFactory<T extends object>(token: CapabilityToken,factory: ServiceFactory<T>,options?: RegisterOptions): void
Registers a lazy factory: the service is instantiated on first
get and cached for subsequent lookups.
unregister(token: CapabilityToken): boolean
Removes a registration. On a multi-provider token this removes EVERY provider registered under it, not just the first.