In Memory Write Repository¶
In-memory write-only repository implementation.
Provides a concrete implementation of WriteOnlyRepository backed by a
dictionary for command-side operations in CQRS architectures.
in_memory_write_repository
¶
In-memory write-only repository implementation.
Provides a concrete implementation of WriteOnlyRepository backed by a
dictionary for command-side operations in CQRS architectures.
InMemoryWriteRepository
¶
Bases: Generic[TWriteAggregateRoot, TWriteId], WriteOnlyRepository[TWriteAggregateRoot, TWriteId]
In-memory implementation of WriteOnlyRepository for command operations.
Stores aggregates in a dictionary keyed by their identifier. Designed
for command-side usage in CQRS architectures.
The storage mapping is injected via the constructor and copied on init
to ensure independence from external mutation.
Source code in src/forging_blocks/infrastructure/repositories/in_memory_write_repository.py
__init__(storage: MutableMapping[TWriteId, TWriteAggregateRoot] | None = None) -> None
¶
Initialize the write repository with optional external storage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
storage
|
MutableMapping[TWriteId, TWriteAggregateRoot] | None
|
An optional mutable mapping to use as backing storage. |
None
|
Source code in src/forging_blocks/infrastructure/repositories/in_memory_write_repository.py
delete_by_id(id: TWriteId) -> None
async
¶
Delete an aggregate by ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
TWriteId
|
Unique identifier of the aggregate. |
required |
Raises:
| Type | Description |
|---|---|
RepositoryError
|
If the ID is None, an empty string, |
RepositoryNotFoundError
|
If no aggregate exists with the given ID. |
Source code in src/forging_blocks/infrastructure/repositories/in_memory_write_repository.py
save(aggregate: TWriteAggregateRoot) -> None
async
¶
Persist an aggregate instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
aggregate
|
TWriteAggregateRoot
|
The aggregate to save. |
required |
Raises:
| Type | Description |
|---|---|
RepositoryError
|
If the aggregate has no valid identifier |