-
Notifications
You must be signed in to change notification settings - Fork 237
/
handler.ex
32 lines (24 loc) · 1.01 KB
/
handler.ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
defmodule Commanded.Commands.Handler do
@moduledoc """
Defines the behaviour a command handler module must implement to support command dispatch.
## Example
An open account handler that delegates to a bank account aggregate:
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
"""
@type aggregate :: struct()
@type command :: struct()
@type domain_event :: struct
@type domain_events :: list(struct())
@type reason :: term()
@doc """
Apply the given command to the event sourced aggregate.
You must return a list containing the pending events, or `nil` / `[]` when no events produced.
You should return `{:error, reason}` on failure.
"""
@callback handle(aggregate, command) :: domain_event | domain_events | nil | {:error, reason}
end