Maestro.Aggregate.CommandHandler behaviour (Maestro v1.0.0)

View Source

Simple behaviour for properly implementing command handlers the way that maestro expects. Its use is not required but is encouraged.

Summary

Callbacks

Command handlers in maestro should implement an eval function that expects to receive the current Root object complete with sequence number and aggregate ID and the incoming command. They should return {:ok, events} on success or {:error, reason} to reject the command.

Types

command()

@type command() :: Maestro.Types.Command.t()

root()

@type root() :: Maestro.Aggregate.Root.t()

uncommitted_event()

@type uncommitted_event() :: Maestro.Types.Event.uncommitted()

Callbacks

eval(root, command)

@callback eval(root(), command()) :: {:ok, [uncommitted_event()]} | {:error, any()}

Command handlers in maestro should implement an eval function that expects to receive the current Root object complete with sequence number and aggregate ID and the incoming command. They should return {:ok, events} on success or {:error, reason} to reject the command.