function resolveRegistryEntry
Since 0.1.0
resolveRegistryEntry<T>(
entry: T | RegistryFactory<T>,
services: IServiceRegistry,
label: string
): T

Resolves one entry of a registration option that accepts either an instance or a RegistryFactory.

A non-function entry is returned unchanged — the instance arm is byte-identical to the pre-factory behaviour. A function entry is called once with services, and its return value is the result. A throw from the factory is wrapped in an Error whose message names label and whose cause is the original, so a factory that resolves a capability the application forgot to register fails start() naming the option and the entry rather than escaping with a bare registry message.

The discrimination is typeof entry === 'function': no instance of any registration contract is callable, and a class — the one shape that is a function and not a factory — is not assignable to RegistryFactory<T>, so passing one is a compile error rather than a runtime TypeError.

Type Parameters

The instance type the option accepts

Parameters

An instance or a factory producing one

The registry handed to a factory

label: string

A human-readable name of the option and entry, for error attribution

Return Type

The resolved instance

Throws

Error

If a factory entry throws; the message names label and the cause is the original error

Usage

import { resolveRegistryEntry } from "common/src/index.ts";