Skip to content

Latest commit

 

History

History
49 lines (33 loc) · 1.24 KB

cqrs.md

File metadata and controls

49 lines (33 loc) · 1.24 KB

Command and query responsibility segregation

Process of registering, requesting handlers.


Table of Contents


Registering

Things to consider:

  • Registering the same name will overwrite the existing handler.
  • Request is supposed to have an name property.

With <handler-name> being the name we use to handle requests with, the <callback> being the callback that will handle the request, TRequest being the type of request and TRequestResponse being the type of response, we register an handler like so:

  mediator.register.handler<TRequest, TRequestResponse>(
    handler-name: string,
    callback: (request: TRequest) => TRequestResponse
  );

Requesting

Things to consider:

  • The request needs to have a name property that corresponsds to the name of the handler.

With <request> being the request object that is passed to handler, TRequest being the type of request and TRequestResponse being the type of response, we handle an request like so:

  let response = mediator.handle<TRequest, TRequestResponse>(
    request: TRequest
    );