In Memory Read Repository¶
In-memory read-only repository implementation.
Provides a concrete implementation of ReadOnlyRepository backed by a
dictionary for query-side operations in CQRS architectures.
in_memory_read_repository
¶
In-memory read-only repository implementation.
Provides a concrete implementation of ReadOnlyRepository backed by a
dictionary for query-side operations in CQRS architectures.
InMemoryReadRepository
¶
Bases: Generic[TReadAggregateRoot, TId], ReadOnlyRepository[TReadAggregateRoot, TId]
In-memory implementation of ReadOnlyRepository for query operations.
Stores aggregates in a dictionary keyed by their identifier. Designed
for query-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_read_repository.py
__init__(storage: Mapping[TId, TReadAggregateRoot] | None = None) -> None
¶
Initialize the read repository with optional external storage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
storage
|
Mapping[TId, TReadAggregateRoot] | None
|
An optional mapping to use as backing storage. |
None
|
Source code in src/forging_blocks/infrastructure/repositories/in_memory_read_repository.py
get_by_id(id: TId) -> TReadAggregateRoot | None
async
¶
Retrieve an aggregate or read model by ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
TId
|
Unique identifier of the resource. |
required |
Returns:
| Type | Description |
|---|---|
TReadAggregateRoot | None
|
The retrieved instance or None if not found. |
Source code in src/forging_blocks/infrastructure/repositories/in_memory_read_repository.py
list_all() -> Sequence[TReadAggregateRoot]
async
¶
Retrieve all resources in the repository.
Returns:
| Type | Description |
|---|---|
Sequence[TReadAggregateRoot]
|
A sequence of aggregate or read model instances. |