pub trait Aggregate: Sized + Send + Sync + Clone {
    type Id: Send + Sync;
    type Event: Message + Send + Sync + Clone;
    type Error: Send + Sync;

    // Required methods
    fn type_name() -> &'static str;
    fn aggregate_id(&self) -> &Self::Id;
    fn apply(
        state: Option<Self>,
        event: Self::Event
    ) -> Result<Self, Self::Error>;
}
Expand description

An Aggregate represents a Domain Model that, through an Aggregate Root, acts as a transactional boundary.

Aggregates are also used to enforce Domain invariants (i.e. certain constraints or rules that are unique to a specific Domain).

Since this is an Event-sourced version of the Aggregate pattern, any change to the Aggregate state must be represented through a Domain Event, which is then applied to the current state using the Aggregate::apply method.

More on Aggregates can be found here: <https://www.dddcommunity.org/library/vernon_2011/>

Required Associated Types§

source

type Id: Send + Sync

The type used to uniquely identify the Aggregate.

source

type Event: Message + Send + Sync + Clone

The type of Domain Events that interest this Aggregate. Usually, this type should be an enum.

source

type Error: Send + Sync

The error type that can be returned by Aggregate::apply when mutating the Aggregate state.

Required Methods§

source

fn type_name() -> &'static str

A unique name identifier for this Aggregate type.

source

fn aggregate_id(&self) -> &Self::Id

Returns the unique identifier for the Aggregate instance.

source

fn apply(state: Option<Self>, event: Self::Event) -> Result<Self, Self::Error>

Mutates the state of an Aggregate through a Domain Event.

§Errors

The method can return an error if the event to apply is unexpected given the current state of the Aggregate.

Object Safety§

This trait is not object safe.

Implementors§