CqrsPlugin(options?: CqrsPluginOptions): IPlugin
Creates the CQRS plugin.
Registers three services:
ICommandBusunderCAPABILITIES.COMMAND_BUSIQueryBusunderCAPABILITIES.QUERY_BUSICqrsFacadeunderCAPABILITIES.CQRS
Single instance only — registering a second CqrsPlugin() throws (duplicate
capability provider, per kernel behavior).
Example 1
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.
optional
options: CqrsPluginOptions
Plugin configuration