[][src]Trait eventually::Aggregate

pub trait Aggregate {
    type Id: Eq;
    type State: Default;
    type Event;
    type Command;
    type Error;
    fn apply(
        state: Self::State,
        event: Self::Event
    ) -> Result<Self::State, Self::Error>;
fn handle<'a, 's>(
        &'a self,
        id: &'s Self::Id,
        state: &'s Self::State,
        command: Self::Command
    ) -> Pin<Box<dyn Future<Output = Result<Option<Vec<Self::Event>>, Self::Error>> + 'a + Send>>
    where
        's: 'a
; }

An Aggregate manages a domain entity State, acting as a transaction boundary.

It allows state mutations through the use of Commands, which the Aggregate instance handles and emits a number of Domain Events.

Associated Types

type Id: Eq

Aggregate identifier: this should represent an unique identifier to refer to a unique Aggregate instance.

type State: Default

State of the Aggregate: this should represent the Domain Entity data structure.

type Event

Represents a specific, domain-related change to the Aggregate State.

type Command

Commands are all the possible operations available on an Aggregate. Use Commands to model business use-cases or State mutations.

type Error

Possible failures while applying Events or handling Commands.

Loading content...

Required methods

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

Applies an Event to the current Aggregate State.

To enforce immutability, this method takes ownership of the previous State and the current Event to apply, and returns the new version of the State or an error.

fn handle<'a, 's>(
    &'a self,
    id: &'s Self::Id,
    state: &'s Self::State,
    command: Self::Command
) -> Pin<Box<dyn Future<Output = Result<Option<Vec<Self::Event>>, Self::Error>> + 'a + Send>> where
    's: 'a, 

Handles the requested Command and returns a list of Events to apply the State mutation based on the current representation of the State.

Loading content...

Implementors

impl<A> Aggregate for AsAggregate<A> where
    A: Aggregate + Send + Sync,
    <A as Aggregate>::Id: Send,
    <A as Aggregate>::Id: Sync,
    <A as Aggregate>::Command: Send,
    <A as Aggregate>::Command: Sync,
    <A as Aggregate>::State: Send,
    <A as Aggregate>::State: Sync
[src]

type Id = <A as Aggregate>::Id

type State = Option<<A as Aggregate>::State>

type Event = <A as Aggregate>::Event

type Command = <A as Aggregate>::Command

type Error = <A as Aggregate>::Error

Loading content...