Commanded v0.14.0-rc.0 Commanded.Commands.Handler behaviour View Source
Defines the behaviour a command handler must implement to support command dispatch.
Example
An open account handler that delegates to a bank account aggregate root:
defmodule OpenAccountHandler do
@behaviour Commanded.Commands.Handler
def handle(%BankAccount{} = aggregate, %OpenAccount{account_number: account_number, initial_balance: initial_balance}) do
BankAccount.open_account(aggregate, account_number, initial_balance)
end
end
Link to this section Summary
Callbacks
Apply the given command to the event sourced aggregate root
Link to this section Types
Link to this section Callbacks
Link to this callback
handle(aggregate, command)
View Source
handle(aggregate, command) :: domain_event | domain_events | nil | {:error, reason}
Apply the given command to the event sourced aggregate root.
You must return a list containing the pending events, or nil
/ []
when no events produced.
You should return {:error, reason}
on failure.