commanded v0.10.0 Commanded.Commands.Router
Command routing macro to allow configuration of each command to its command handler.
Example
defmodule BankRouter do
use Commanded.Commands.Router
dispatch OpenAccount, to: OpenAccountHandler, aggregate: BankAccount, identity: :account_number
end
:ok = BankRouter.dispatch(%OpenAccount{account_number: "ACC123", initial_balance: 1_000})
The command handler module must implement a handle/2
function that receives the aggregate’s state and the command to execute.
It should delegate the command to the aggregate.
It is also possible to route a command directly to an aggregate root. Without requiring an intermediate command handler.
Example
defmodule BankRouter do
use Commanded.Commands.Router
dispatch OpenAccount, to: BankAccount, identity: :account_number
end
The aggregate root must implement an execute/2
function that receives the aggregate’s state and the command to execute.
Summary
Functions
Dispatch the given command to the corresponding handler for a given aggregate root uniquely identified
Include the given middleware module to be called before and after success or failure of each command dispatch
Functions
Dispatch the given command to the corresponding handler for a given aggregate root uniquely identified
Include the given middleware module to be called before and after success or failure of each command dispatch
Middleware modules are executed in the order they’ve been defined.