# `Decree.Middleware.ExtractAggregateIdentity`
[🔗](https://github.com/sparkle-space/decree/blob/v0.1.0/lib/decree/middleware/extract_aggregate_identity.ex#L1)

An internal `Decree.Middleware` that extracts the target aggregate's
identity from the command.

It runs after every middleware a router registers, and after `Decree.Middleware.CommandId`,
so it reads the command they leave. It resolves the identity once per dispatch, and assigns
it twice: `:aggregate_uuid` is the stream name, with any `identify` prefix, and
`:aggregate_identity` is the same string before the prefix.

The identity is checked as the command's field, or the route's identity function, gave it,
before the prefix: it must be a lowercase canonical UUID (`Decree.UUID.canonical?/1`), or,
on a route declared `opaque: true`, a non-empty binary. Anything else, a missing field and
nil included, answers `{:error, :invalid_aggregate_identity}` and halts. Nothing converts,
trims or downcases it, so the stream is named by exactly what the requester sent.

# `after_dispatch`

# `after_failure`

# `before_dispatch`

---

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