[−][src]Struct cqrs_es::CqrsFramework
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
.
Methods
impl<A, E, ES> CqrsFramework<A, E, ES> where
A: Aggregate,
E: DomainEvent<A>,
ES: EventStore<A, E>,
[src]
A: Aggregate,
E: DomainEvent<A>,
ES: EventStore<A, E>,
pub fn new(
store: ES,
query_processors: Vec<Box<dyn QueryProcessor<A, E>>>
) -> CqrsFramework<A, E, ES> where
A: Aggregate,
E: DomainEvent<A>,
ES: EventStore<A, E>,
[src]
store: ES,
query_processors: Vec<Box<dyn QueryProcessor<A, E>>>
) -> CqrsFramework<A, E, ES> where
A: Aggregate,
E: DomainEvent<A>,
ES: EventStore<A, E>,
Creates new framework for dispatching commands using the provided elements.
pub fn execute<C: Command<A, E>>(
&self,
aggregate_id: &str,
command: C
) -> Result<(), AggregateError>
[src]
&self,
aggregate_id: &str,
command: C
) -> Result<(), AggregateError>
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<C: Command<A, E>>(
&self,
aggregate_id: &str,
command: C,
metadata: HashMap<String, String>
) -> Result<(), AggregateError>
[src]
&self,
aggregate_id: &str,
command: C,
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.
Auto Trait Implementations
impl<A, E, ES> !RefUnwindSafe for CqrsFramework<A, E, ES>
impl<A, E, ES> !Send for CqrsFramework<A, E, ES>
impl<A, E, ES> !Sync for CqrsFramework<A, E, ES>
impl<A, E, ES> Unpin for CqrsFramework<A, E, ES> where
ES: Unpin,
ES: Unpin,
impl<A, E, ES> !UnwindSafe for CqrsFramework<A, E, ES>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,