interface CommandHandlerRegistration
Since 0.1.0

One command handler and the command type the bus routes to it.

A PAIR rather than a bare handler because that is exactly what ICommandBus.register(type, handler) takes: the type is a string the command carries, and deriving it from the handler's class name would invent a second source of truth for the same value.

The handler is typed at ICommandHandler's defaults (CqrsCommand, unknown) so a heterogeneous list of concretely-typed handlers is assignable without any: handle is declared with METHOD syntax, so TypeScript compares its parameter bivariantly even under strictFunctionTypes.

Properties

readonly
type: string

Command type name, matching command.type.

readonly
handler: ICommandHandler | RegistryFactory<ICommandHandler>

The handler to register for that type, or a factory that builds one from the service registry.

An instance registers on the bus during register(). A factory is called at the onInit phase — after every plugin has registered — and its result is registered under this entry's type, so it can resolve a capability (the event bus, the logger) its contract's message parameter cannot carry.

Usage

import { type CommandHandlerRegistration } from "cqrs-plugin/src/index.ts";