Skip to content

Repositories

In Comby, repositories play a central role in managing and interacting with domain-specific entities and their associated data. They act as a bridge between the application logic and the underlying storage systems. Repositories enable developers to work seamlessly with Aggregates,Commands, and Events without dealing directly with the intricacies of the underlying stores.

Without repositories, we would have to work directly with the respective stores and handle the deserialization of domain-specific data ourselves, which is highly inefficient. Additionally, repositories split certain requests into multiple requests to the stores to load data as needed. This functionality is beyond the capability of the stores themselves and is intentionally not their responsibility. In comby, we keep things simple and stupid.

INFO

In comby, persisting commands is optional. If enabled, commands can be retrieved from the CommandRepository or directly in raw format via the CommandStore. Queries, on the other hand, are never persisted, which is why there is no QueryRepository or QueryStore in the framework.

Event Repository

The EventRepository manages the lifecycle of domain events. It provides methods to add, retrieve, list, and delete events from the underlying EventStore. The repository ensures that events are properly loaded and enriched with their corresponding domain event data via the DomainEventProvider. This abstraction is key in event-sourced architectures, allowing aggregates to reconstruct their state by replaying stored events.

Aggregate Repository

The AggregateRepository is responsible for managing aggregates and their state. It uses the EventRepository to fetch and apply events for reconstructing aggregate state. Developers can retrieve specific versions of an aggregate, list aggregates, and even delete them. By abstracting the logic for state reconstruction, the AggregateRepository simplifies working with aggregates in event-sourced systems.

Command Repository

The CommandRepository handles the persistence and retrieval of commands. It interacts with the CommandStore to store and retrieve commands efficiently. The repository also integrates with the DomainCommandProvider to deserialize and enrich commands with domain-specific data. This is particularly useful in systems leveraging CQRS, where commands represent the intent to change state.