Setu-TS
    Preparing search index...

    Interface IServiceRegistry

    Maps capability tokens to service instances.

    The registry is the framework's primary service resolution mechanism; the optional DI container is a convenience layer on top of it. The application registry is sealed after runBootstrap(); request-scoped services are registered on the request context instead.

    // Provider plugin
    ctx.services.register(CAPABILITIES.CACHE, new RedisCacheStore(options));

    // Consumer plugin
    const cache = ctx.services.get<ICacheStore>(CAPABILITIES.CACHE);

    0.1.0

    interface IServiceRegistry {
        get<T extends object>(token: string): T;
        getAll<T extends object>(token: string): readonly T[];
        has(token: string): boolean;
        isCurrent?<T extends object>(token: string, instance: T): boolean;
        register<T extends object>(
            token: string,
            service: T,
            options?: RegisterOptions,
        ): void;
        registerFactory<T extends object>(
            token: string,
            factory: ServiceFactory<T>,
            options?: RegisterOptions,
        ): void;
        unregister(token: string): boolean;
    }

    Implemented by

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

    • Reports whether a capability is available.

      Parameters

      • token: string

        The capability token to look up

      Returns boolean

      true if at least one provider is registered

    • Reports whether a known instance is the CURRENT provider a resolving get would select for a token — WITHOUT resolving it.

      This is a non-resolving identity check: it compares the supplied instance against the registration get would choose (own single registration, then own first multi-provider, then the parent) and returns a boolean. It never invokes a lazy factory, never returns the current service, and never enumerates the registry. A token whose selected registration is a factory that has not yet run answers false, not the parent's instance: "present but never constructed" must not be mistaken for a foreign provider.

      The method is OPTIONAL so that third-party registry-shaped test doubles and request-scoped contexts that predate it keep compiling. A consumer that needs a current-provider check must treat an absent isCurrent as "cannot verify" rather than falling back to get, which would instantiate a lazy replacement.

      Type Parameters

      • T extends object

        The service's interface type

      Parameters

      • token: string

        The capability token to check

      • instance: T

        The instance to compare against the current registration

      Returns boolean

      true only when instance IS the registration get would select

      0.8.0

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