Seven.Otters.Aggregate (Seven Otters v0.8.0) View Source

Provides the use macro to create an aggregate.

Example:

defmodule SevenCommerce.Aggregates.User do
  use Seven.Otters.Aggregate, aggregate_field: :id

  defstruct id: nil,
            user: nil,
            password: nil,
            cart: []

  defp init_state, do: %__MODULE__{}

  defp pre_handle_command(_command, _state), do: :ok
  defp handle_command(_command, _state), do: {:managed, []}
  defp handle_event(_event, state), do: state
end

Module must declare the use of Seven.Otters.Aggregate module, specifying the field to use as correlation id; the field must be present in module structure:

use Seven.Otters.Aggregate, aggregate_field: :id

defstruct id: nil,
          ...

Some function must be implemented in the aggregate.