Repository
Bases: Generic[TAggregate]
Repository for event-sourced aggregates.
Provides loading and persisting of aggregates using an event store. Handles event replay to reconstruct aggregate state and persists new events emitted by the aggregate.
Source code in event_sourcery/event_sourcing/repository.py
aggregate(uuid, aggregate, context=None)
Context manager for loading an aggregate instance.
Loads the aggregate's event stream, replays events to reconstruct its state,
yields a WrappedAggregate containing the aggregate and stream metadata,
and persists any new events emitted during the context.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uuid
|
StreamUUID
|
The unique identifier of the aggregate's stream. |
required |
aggregate
|
TAggregate
|
The aggregate initial instance to load state into. |
required |
context
|
Context | None
|
Optional context to attach to all emitted events. |
None
|
Yields:
| Type | Description |
|---|---|
WrappedAggregate[TAggregate]
|
WrappedAggregate[TAggregate]: The aggregate wrapped with stream metadata. |