Aggregate Repository¶
aggregate_repository
¶
Aggregate RepositoryPort implementation.
Provides a repository specifically designed for AggregateRoot persistence
with event sourcing support.
AggregateRepository
¶
Bases: BaseRepository[TAggregateRoot, TId]
RepositoryPort for AggregateRoot persistence with event sourcing.
Extends BaseRepository with event store integration for
event-sourced aggregates.
Source code in src/forging_blocks/infrastructure/repositories/aggregate_repository.py
__init__(event_store: EventStorePort, storage: dict[TId, TAggregateRoot] | None = None) -> None
¶
Initialize the aggregate repository.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event_store
|
EventStorePort
|
The event store for persisting domain events. |
required |
storage
|
dict[TId, TAggregateRoot] | None
|
Optional in-memory storage for aggregate snapshots. |
None
|
Source code in src/forging_blocks/infrastructure/repositories/aggregate_repository.py
save(aggregate: TAggregateRoot) -> None
async
¶
Save an aggregate and its uncommitted events.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
aggregate
|
TAggregateRoot
|
The aggregate to save. |
required |
Source code in src/forging_blocks/infrastructure/repositories/aggregate_repository.py
get_by_id(id: TId) -> TAggregateRoot | None
async
¶
Retrieve an aggregate by ID and replay its events.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
TId
|
Unique identifier of the aggregate. |
required |
Returns:
| Type | Description |
|---|---|
TAggregateRoot | None
|
The retrieved aggregate or None if not found. |