Implementing Domain Service TypeScript

Now that the design of the project is done, the next step is to implement it. You can find helpful information on preparing your IDE in development tools. This also includes the installation and setup of the Solution CLI which provides several features related to local development as well as testing service projects.

Note:

This part will be done in the IDE of your choice.

Introduction

The implementation of a Domain Service Project is focused on the usage of commands, services, events and operations. These are the main elements to add functional behavior to the project.

While working on a REST API you will implement mostly operations and maybe call domain services to process the incoming request. Depending on your project's design you may need to gather additional data from an integration service that will then be processed and enriched with other data by using a domain service.

Warning:

Whenever you are querying external services, you should make sure, that all communication to such services are encrypted and all TLS-encrypted protocols including HTTPS use version 1.2+. The connection to the target service should be authenticated (certificate validation should be enabled)!

There is also the option to create, edit and persist data or load data from the datastore by using factory commands or instance commands. This domain service could also publish an event whenever a request has been processed or data has been created/persisted.

To make proper use of these elements you need to understand when and how to use which of them to implement the desired behavior. Below is a description of each element, its intended use and scope of other elements it can call.

Functional overview

Factory command

  • Creates an instance of a root entity and persists it in the data-store
  • Inside a factory command, events can be published.
  • Inside a factory command's implementation, there is a function called available(). This is used to check the necessary pre-conditions of the command. If the function returns true then the command will be executed, otherwise, the command will not be executed at all.

Instance command

  • Manipulates the values of one or more properties of an already existing instance of an entity
  • Inside an instance command, events can be published
  • Inside an instance command's implementation, there is a function called available(). This is used to check the necessary pre-conditions of the command. If the function returns true then the command will be executed, otherwise, the command will not be executed at all.

Domain service

  • can perform operations throughout different Domain Namespaces
  • inside a domain service, you can call factory commands, instance commands, domain services, and events

Events

  • they are published to indicate that some state has changed
  • an event that is successfully published will automatically execute the script of the agent that is bound to this event

Agents

  • when an event is triggered, then agents are automatically executed as consequence of the action that triggered the event
  • inside agents, you can call factory commands, instance commands, domain services and trigger events

Operations

  • Can perform operations throughout different Domain Namespaces
  • Inside operations, you can call factory commands, instance commands and domain services

Scope overview

Factory commandInstance commandDomain serviceEventsAgentsOperation
Factory command o
Instance command o
Domain serviceoooo
Events o
Agentsoooo
Operationooo