[][src]Struct cqrs_es::CqrsFramework

pub struct CqrsFramework<A, E, ES> where
    A: Aggregate,
    E: DomainEvent<A>,
    ES: EventStore<A, E>, 
{ /* fields omitted */ }

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:

  1. loading all previous events for the aggregate instance
  2. applying these events, in order, to a new Aggregate
  3. using the recreated Aggregate to handle an inbound Command
  4. 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]

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]

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]

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 QueryProcessors.

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]

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 QueryProcessors.

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

impl<A, E, ES> !UnwindSafe for CqrsFramework<A, E, ES>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.