Struct cqrs_es2::CqrsFramework [−][src]
pub struct CqrsFramework<A, ES, AC> where
A: Aggregate,
ES: EventStore<A, AC>,
AC: AggregateContext<A>, { /* fields omitted */ }
Expand description
This is the base framework for applying commands to produce events.
In Domain Driven Design we require that
changes are made only after loading the entire Aggregate
in
order to ensure that the full context is understood.
With event-sourcing this means:
- loading all previous events for the aggregate instance
- applying these events, in order, to a new
Aggregate
- using the recreated
Aggregate
to handle an inboundCommand
- persisting any generated events or rolling back on an error
To manage these tasks we use a CqrsFramework
.
Implementations
impl<A, ES, AC> CqrsFramework<A, ES, AC> where
A: Aggregate,
ES: EventStore<A, AC>,
AC: AggregateContext<A>,
impl<A, ES, AC> CqrsFramework<A, ES, AC> where
A: Aggregate,
ES: EventStore<A, AC>,
AC: AggregateContext<A>,
pub fn new(
store: ES,
query_processors: Vec<Box<dyn QueryProcessor<A>>>
) -> CqrsFramework<A, ES, AC> where
A: Aggregate,
ES: EventStore<A, AC>,
AC: AggregateContext<A>,
pub fn new(
store: ES,
query_processors: Vec<Box<dyn QueryProcessor<A>>>
) -> CqrsFramework<A, ES, AC> where
A: Aggregate,
ES: EventStore<A, AC>,
AC: AggregateContext<A>,
Creates new framework for dispatching commands using the provided elements.
This applies a command to an aggregate. Executing a command in this way is the only way to make any change to the state of an aggregate.
An error while processing will result in no events committed and an AggregateError being returned.
If successful the events produced will be applied to the
configured QueryProcessor
s.
Error
If an error is generated while processing the command this will be returned.
pub fn execute_with_metadata(
&mut self,
aggregate_id: &str,
command: A::Command,
metadata: HashMap<String, String>
) -> Result<(), AggregateError>
pub fn execute_with_metadata(
&mut self,
aggregate_id: &str,
command: A::Command,
metadata: HashMap<String, String>
) -> Result<(), AggregateError>
This applies a command to an aggregate along with associated metadata. Executing a command in this way to make any change to the state of an aggregate.
A Hashmap<String,String>
is supplied with any contextual
information that should be associated with this change.
This metadata will be attached to any produced events and is
meant to assist in debugging and auditing. Common information
might include:
- time of commit
- user making the change
- application version
An error while processing will result in no events committed and an AggregateError being returned.
If successful the events produced will be applied to the
configured QueryProcessor
s.