Services

Services are defined in the model/services.ts file.

For each service, we define what commands and models the services produces and consumes.

For example:

export class OMS extends Service {
	consumes = [Commands.NewOrder, Commands.CancelOrder, Models.ExchangeOrder];

	produces = [
		Commands.NewExchangeOrder,
		Commands.CancelExchangeOrder,
		Models.Order,
	];
}

Declaring the commands that a service consumes and produces allows us to:

  • produce a service scaffold that contains hook points for only those commands, ensuring that the implementation adheres to the service's contract;
  • statically verify that:
    • commands that are consumed are published, and
    • commands that are published are consumed.

Declaring the models that are consumed and produced by the service allows us to:

  • validate that there is a single source of truth for every class of data (only one service may publish any model);
  • validate that each model is in fact published by a service;
  • consume and cache the right data in memory in each service.