class MockServiceRegistry
implements IServiceRegistry
Since 0.1.0

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:

  • get resolves a factory once and caches it; on a miss throws the kernel's verbatim two-sentence message.
  • getAll returns [...(single ? [single] : []), ...multi] — the single registration is included, not just the multi list.
  • register/registerFactory honor RegisterOptions exactly: multi: true appends; otherwise a second registration throws unless override: true replaces it.
  • has checks both maps; unregister deletes from both.
  • A readonly registrations field records every call.

Properties

readonly
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.

Methods

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.

Usage

import { MockServiceRegistry } from "testing/src/index.ts";