interface IServiceRegistry
Since 0.1.0

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.

Examples

Example 1

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

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

Methods

register<T extends object>(
service: T,
options?: RegisterOptions
): void

Registers a service instance under a capability token.

registerFactory<T extends object>(
factory: ServiceFactory<T>,
options?: RegisterOptions
): void

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

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.

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 { type IServiceRegistry } from "common/src/index.ts";