class CommandBus
implements ICommandBus
Since 0.1.0

Concrete command bus implementing ICommandBus.

Constructors

CommandBus(behaviors?: readonly IPipelineBehavior[])

Creates a new command bus.

Parameters
optional
behaviors: readonly IPipelineBehavior[]

Behaviors to apply to every command execution (default: [])

Properties

readonly
handlerCount: number

The number of registered command handlers.

INTERNAL: not part of the ICommandBus interface.

Methods

clear(): void

Clears all registered command handlers.

INTERNAL: not part of the ICommandBus interface.

execute<TResult = unknown>(command: CqrsCommand): Promise<TResult>

Executes a command.

register<TCommand extends CqrsCommand, TResult>(
type: string,
handler: ICommandHandler<TCommand, TResult>
): void

Registers a command handler.

setBehaviors(behaviors: readonly IPipelineBehavior[]): void

Replaces the behavior list.

INTERNAL: not part of the ICommandBus interface.

Usage

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