pub struct CqrsCommandEngine<A>{ /* private fields */ }Expand description
The CqrsCommandEngine struct is a Command Query Responsibility Segregation (CQRS) engine
designed to handle commands and communication with an underlying event store and various dispatchers.
It acts as the main entry point for command processing and encapsulates the behavior specific to an aggregate.
§Type Parameters
A: The type of the aggregate managed by this CQRS engine. The aggregate represents the domain behavior and state transitions.ES: The type of the event store used to views events related to the aggregate.
§Bounds
A: Must implement theAggregatetrait. This ensures the aggregate provides necessary functionality such as validating commands or applying events to mutate its state.ES: Must implement theEventStore<A>trait. This ensures the event store works with the specified aggregate type for persisting and retrieving events.
§Fields
-
store: ESThe event store instance used to views and retrieve events associated with the aggregate. It allows the CQRS engine to save and load the aggregate’s event stream to/from persistent storage. -
dispatchers: Vec<Box<dyn Dispatcher<A>>>A collection of dispatchers used by the CQRS engine to handle various external interactions such as messaging or integration with other systems. Dispatchers are responsible for forwarding or broadcasting events and can implement custom logic based on the use case. -
services: A::ServicesA collection of domain-specific services required by the aggregate to perform its business operations. These services are defined within the aggregate’s associated types to provide dependencies such as external APIs, configuration, or infrastructure required for executing commands.
§Usage
Typically, the CqrsCommandEngine is instantiated with a concrete implementation of an event store,
one or more command dispatchers, and the services needed by the aggregate. Once initialized,
it can be used to dispatch commands and manage the lifecycle of aggregate instances.
This struct facilitates the CQRS pattern by separating the responsibility of command handling from querying, while keeping event storage and dispatching modular and configurable.