Command
Commands form the API of your domain. Like Events, they are simple data objects.
Commands have descriptive names describing the intent of what you are trying to achieve, for example CreateUser
or SendInvoice
.
Commands inherit from Sequent::Command
. Additionally
you can add Validations to commands to ensure correctness. Sequent uses
ActiveModel::Validations
to enable validations.
An example of a CreateUser
Command, with basic validations:
class CreateUser < Sequent::Command
attrs firstname: String, lastname: String
validates_presence_of :firstname, :lastname
end
Commands, like Events, are also stored in the EventStore.
Typically when building a web application, you will bind an html form to a Command
. You then have to pass
it into the CommandService. The CommandService will only execute valid Commands.
When a Command is valid, the CommandHandlers registered and interested in this Command
will be invoked.
When a Command is not valid, a Sequent::Core::CommandNotValid
will be raised containing the validation errors.