[][src]Trait domain_patterns::collections::EventRepository

pub trait EventRepository {
    type Events: DomainEvent;
    fn events_by_aggregate(
        &self,
        aggregate_id: &String
    ) -> Option<Vec<Self::Events>>;
fn events_since_version(
        &self,
        aggregate_id: &String,
        version: u64
    ) -> Option<Vec<Self::Events>>;
fn num_events_since_version(
        &self,
        aggregate_id: &String,
        version: u64,
        num_events: u64
    ) -> Option<Vec<Self::Events>>;
fn get(&self, event_id: &String) -> Option<Self::Events>;
fn contains_aggregate(&self, aggregate_id: &String) -> bool;
fn insert(&mut self, event: &Self::Events) -> Option<Self::Events>; fn contains_event(&self, event_id: &String) -> bool { ... } }

EventRepository is a trait that provides collection like semantics over event storage and retrival. The implementor may choose to persist and retrieve events from any storage mechanism of their choosing.

Associated Types

type Events: DomainEvent

Events should likely be pointed at an enum that holds domain event variants. All variants should implement DomainEvent trait, and the enum itself should also implement DomainEvent trait. This is trivial if you're using the domain_derive crate, in which case you can simply use the DomainEvent macro on each DomainEvent, and then the DomainEvents macro on the enum holding you DomainEvent variants.

Loading content...

Required methods

fn events_by_aggregate(
    &self,
    aggregate_id: &String
) -> Option<Vec<Self::Events>>

events_by_aggregate returns a vector of pointers to events filtered by the supplied aggregate id.

fn events_since_version(
    &self,
    aggregate_id: &String,
    version: u64
) -> Option<Vec<Self::Events>>

events_since_version will give the caller all the events that have occurred for the given aggregate id since the version number supplied.

fn num_events_since_version(
    &self,
    aggregate_id: &String,
    version: u64,
    num_events: u64
) -> Option<Vec<Self::Events>>

num_events_since_version provides a vector of events of a length equal to the supplied num_events integer, starting from version + 1, and going up to version + num_events in sequential order.

Used for re-hydrating aggregates, where the aggregate root can ask for chunks of events that occurred after it's current version number.

fn get(&self, event_id: &String) -> Option<Self::Events>

Returns the event if it exists that corresponds to the supplied event_id as an owned type.

fn contains_aggregate(&self, aggregate_id: &String) -> bool

Returns a bool letting the caller know if the event repository contains any events associated with the aggregate id.

fn insert(&mut self, event: &Self::Events) -> Option<Self::Events>

Inserts a new domain event into the event store.

Loading content...

Provided methods

fn contains_event(&self, event_id: &String) -> bool

Returns a boolean indicating whether the event repository contains the event by the supplied id.

Loading content...

Implementors

Loading content...