function CqrsPlugin
Since 0.1.0
CqrsPlugin(options?: CqrsPluginOptions): IPlugin

Creates the CQRS plugin.

Registers three services:

  • ICommandBus under CAPABILITIES.COMMAND_BUS
  • IQueryBus under CAPABILITIES.QUERY_BUS
  • ICqrsFacade under CAPABILITIES.CQRS

Single instance only — registering a second CqrsPlugin() throws (duplicate capability provider, per kernel behavior).

Examples

Example 1

import { CqrsPlugin } from '@setu-ts/cqrs-plugin';

app.register(CqrsPlugin({
  behaviors: [timingBehavior],
  commandHandlers: [
    { type: CREATE_USER, handler: new CreateUserHandler() },
    { type: PLACE_ORDER, handler: createPlaceOrderCommandHandler },
  ],
  queryHandlers: [{ type: GET_USER, handler: new GetUserHandler() }],
}));

commandHandlers, queryHandlers, and behaviors each accept an instance or a RegistryFactory ((services: IServiceRegistry) => T). A factory is resolved at onInit — the first phase at which the registry holds every capability — so it can resolve any capability and build the handler or behavior with it. Instance entries keep their register() timing.

Parameters

optional
options: CqrsPluginOptions

Plugin configuration

Return Type

IPlugin

The plugin instance

Usage

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