Trait esrs::aggregate::AggregateManager[][src]

pub trait AggregateManager: Identifier {
    type State: Default + Clone + Debug + Send + Sync;
    type Command: Send + Sync;
    type Event: Serialize + DeserializeOwned + Send + Sync;
    type Error: Send + Sync;
    fn event_store(
        &self
    ) -> &(dyn EventStore<Self::Event, Self::Error> + Send + Sync);
fn apply_event(
        id: &Uuid,
        state: Self::State,
        event: &StoreEvent<Self::Event>
    ) -> Self::State;
fn validate_command(
        aggregate_state: &AggregateState<Self::State>,
        cmd: &Self::Command
    ) -> Result<(), Self::Error>;
fn do_handle_command<'life0, 'async_trait>(
        &'life0 self,
        aggregate_state: AggregateState<Self::State>,
        cmd: Self::Command
    ) -> Pin<Box<dyn Future<Output = Result<AggregateState<Self::State>, Self::Error>> + Send + 'async_trait>>
    where
        'life0: 'async_trait,
        Self: 'async_trait
; fn handle_command<'life0, 'async_trait>(
        &'life0 self,
        aggregate_state: AggregateState<Self::State>,
        cmd: Self::Command
    ) -> Pin<Box<dyn Future<Output = Result<AggregateState<Self::State>, Self::Error>> + Send + 'async_trait>>
    where
        'life0: 'async_trait,
        Self: Sync + 'async_trait
, { ... }
fn apply_events(
        aggregate_state: AggregateState<Self::State>,
        events: Vec<StoreEvent<Self::Event>>
    ) -> AggregateState<Self::State> { ... }
fn load<'life0, 'async_trait>(
        &'life0 self,
        aggregate_id: Uuid
    ) -> Pin<Box<dyn Future<Output = Option<AggregateState<Self::State>>> + Send + 'async_trait>>
    where
        'life0: 'async_trait,
        Self: Sync + 'async_trait
, { ... }
fn persist<'life0, 'async_trait>(
        &'life0 self,
        aggregate_state: AggregateState<Self::State>,
        events: Vec<Self::Event>
    ) -> Pin<Box<dyn Future<Output = Result<AggregateState<Self::State>, Self::Error>> + Send + 'async_trait>>
    where
        'life0: 'async_trait,
        Self: Sync + 'async_trait
, { ... } }
Expand description

The AggregateManager is responsible for loading an aggregate from the store, mapping commands to events, and persisting those events in the store. Be careful when implenting this trait, as you will be responsible for threading AggregateState/Commands/Events correctly. For example, a bad implementation could result in an AggregateState that is not replicated on load.

Unless you need to perform side effects as part of your command handling/verification you should implement the safer Aggregate trait instead.

Associated Types

Required methods

Returns the event store, configured for the aggregate

This function applies the event onto the aggregate and returns a new one, updated with the event data

Validation should reject any command is inconsitent with the current aggregate state, or would result in one or more events that could not be applied onto the aggregate state.

Provided methods

Responsible for applying events in order onto the aggregate state, and incrementing the sequence number. You should avoid implementing this method, and be very careful if you decide to do so.

events will be passed in order of ascending sequence number.

Loads an aggregate instance from the event store, by applying previously persisted events onto the aggregate state by order of their sequence number

Persits an event into the event store - recording it in the aggregate instance’s history.

Implementors