Setu-TS
    Preparing search index...

    Class MockServiceRegistry

    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.

    0.1.0

    Implements

    Index
    • get registrations(): readonly { multi: boolean; token: string }[]

      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.

      Returns readonly { multi: boolean; token: string }[]

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

      Type Parameters

      • T extends object

        The expected service type

      Parameters

      • token: string

        The capability token to resolve

      Returns T

      The registered service

      If no service is registered for the token

    • Resolves every provider registered for a multi-provider token.

      Type Parameters

      • T extends object

        The expected service type

      Parameters

      • token: string

        The capability token to resolve

      Returns readonly T[]

      All registered providers, in registration order; empty when none

    • Registers a service instance under a capability token.

      Type Parameters

      • T extends object

        The service type

      Parameters

      • token: string

        The capability token to register under

      • service: T

        The service instance

      • Optionaloptions: RegisterOptions

        Override and multi-provider behavior

      Returns void

      If the token is already registered and neither override nor multi is set

      If called after the application has run runBootstrap()

      override: true is reported through the logger capability.

    • Registers a lazy factory: the service is instantiated on first get and cached for subsequent lookups.

      Type Parameters

      • T extends object

        The service type

      Parameters

      • token: string

        The capability token to register under

      • factory: ServiceFactory<T>

        Factory invoked once, on first lookup

      • Optionaloptions: RegisterOptions

        Override and multi-provider behavior

      Returns void

      If the token is already registered and neither override nor multi is set

      If called after the application has run runBootstrap()

      override: true is reported through the logger capability.

    • Removes a registration. On a multi-provider token this removes EVERY provider registered under it, not just the first.

      Parameters

      • token: string

        The capability token to remove

      Returns boolean

      true if a registration was removed

      If called after the application has run runBootstrap()

      A successful unregister is reported through the logger capability. Prefer register(token, service, { override: true }) for a replacement during bootstrap.