# `Decree.Aggregates.ExecutionContext`
[🔗](https://github.com/sparkle-space/decree/blob/v0.1.0/lib/decree/aggregates/execution_context.ex#L1)

Defines the arguments used to execute a command for an aggregate.

The available options are:

  - `command` - the command to execute, typically a struct
    (e.g. `%OpenBankAccount{...}`).

  - `retry_attempts` - the number of retries permitted if an
    `{:error, :wrong_expected_version}` is encountered when appending events.

  - `causation_id` - the UUID assigned to the dispatched command.

  - `correlation_id` - a UUID used to correlate related commands/events.

  - `metadata` - a map of key/value pairs containing the metadata to be
    associated with all events created by the command.

  - `handler` - the module that handles the command. It may be either the
    aggregate module itself or a separate command handler module.

  - `function` - the name of the function, as an atom, that handles the command.
    The default value is `:execute`, used to support command dispatch directly
    to the aggregate module. For command handlers the `:handle` function is
    used.

  - `before_execute` - the name of the function, as an atom, that prepares the
    command before execution, called just before `function`. The default value
    is `nil`, disabling it. It should return `:ok` on success or `{:error, any()}`
    to cancel the dispatch.

  - `lifespan` - a module implementing the `Decree.Aggregates.AggregateLifespan`
    behaviour to control the aggregate instance process lifespan. The default
    value, `Decree.Aggregates.DefaultLifespan`, keeps the process running
    indefinitely.

  - `identity` - how the route finds the aggregate's identity: the name of a command
    field, or a one argument function returning it. Only
    `Decree.Event.Append.prepare/4` reads it, and only for the kind of the stream's
    entity tag. It is not called for that: `aggregate_identity` is what it resolved to.

  - `aggregate_identity` - the identity the stream was routed by, as the string
    `Decree.Middleware.ExtractAggregateIdentity` resolved once for the dispatch, before
    any `identify` prefix. It is the id of the stream's entity tag. It is `nil` for a
    context not built by a dispatch, which gives no stream tag.

  - `stream_tag` - the kind the route named for the stream's entity tag, an atom, or
    `nil`. See `Decree.Commands.Router.dispatch/2`.

  - `rule` - the route's `Decree.Decision.Rule`, or `nil`. What its read answers never
    reaches this struct: `command` stays the plain command.

  - `rule_retries` - the number of retries permitted if a rule's condition, or a windowed
    aggregate's, fails, set from `retry_attempts` and spent apart from it, so neither loop
    spends the other's budget.

  - `attempt` - the number of this attempt at the command in this dispatch, which a rule's
    telemetry reports.

# `t`

```elixir
@type t() :: %Decree.Aggregates.ExecutionContext{
  aggregate_identity: term(),
  attempt: term(),
  before_execute: term(),
  causation_id: term(),
  command: term(),
  correlation_id: term(),
  function: term(),
  handler: term(),
  identity: term(),
  lifespan: term(),
  metadata: term(),
  retry_attempts: term(),
  returning: term(),
  rule: term(),
  rule_retries: term(),
  stream_tag: term()
}
```

# `format_reply`

# `retry`

---

*Consult [api-reference.md](api-reference.md) for complete listing*
