Trigger Commands

The generated SDK provides functions to easily trigger commands from other places in the service.

Input entity

When triggering a command, it might be necessary to provide an input entity. The Entity factory can be used to create new input entities, which could be set as input parameter for the command.

Trigger factory commands

Factory commands can be triggered through the provided Repository, which holds an object for each root entity, grouped by domain namespace.

The following code shows how to trigger a factory command, for example from a service implementation.

// Initialize the input 
const input = this.factory.entity.nsacrnm.FactoryCommandIdentifier_Input();
input.property1 = "value";

// Access the repository of the specific root entity and choose the factory command
const rootEntityInstance = await this.repo.nsacrnm.RootEntityIdentifier.FactoryCommandIdentifier(input)

// Access the id of the root entity instance
rootEntityInstance._id;

// Access the properties of the root entity instance
rootEntityInstance.property1;

Trigger instance commands

Instance commands can be executed on instances of aggregates, which were usually loaded before from the database by using the Repository or returned from a factory command.

The following code shows how to trigger an instance command, for example from a service implementation.

// Initialize the input 
// Access the repository of the specific root entity and choose the the factory command or search for a specific instance of the root entity
// Here we call a factory command
const rootEntityInstance = await this.repo.nsacrnm.RootEntityIdentifier.FactoryCommandIdentifier(input)

// Initialize the input 
const input = this.factory.entity.nsacrnm.InstanceCommandIdentifier_Input();
input.property1 = "value";

// From the returned root entity instance, it is possible to access the instance commands that are related to this instance and execute them accordingly
await rootEntityInstance.InstanceCommandIdentifier(input);