class QueryBus
implements IQueryBus
Since 0.1.0

Concrete query bus implementing IQueryBus.

Constructors

QueryBus(behaviors?: readonly IPipelineBehavior[])

Creates a new query bus.

Parameters
optional
behaviors: readonly IPipelineBehavior[]

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

Properties

readonly
handlerCount: number

The number of registered query handlers.

INTERNAL: not part of the IQueryBus interface.

Methods

clear(): void

Clears all registered query handlers.

INTERNAL: not part of the IQueryBus interface.

execute<TResult = unknown>(query: CqrsQuery): Promise<TResult>

Executes a query.

register<TQuery extends CqrsQuery, TResult>(
type: string,
handler: IQueryHandler<TQuery, TResult>
): void

Registers a query handler.

setBehaviors(behaviors: readonly IPipelineBehavior[]): void

Replaces the behavior list.

INTERNAL: not part of the IQueryBus interface.

Usage

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