Struct EventSourcedOrchestratingAggregate

Source
pub struct EventSourcedOrchestratingAggregate<'a, C, S, E, Repository, Version, Error>
where Repository: EventRepository<C, E, Version, Error>,
{ /* private fields */ }
Expand description

Orchestrating Event Sourced Aggregate. It is using a Decider and Saga to compute new events based on the current events and the command. If the decider is combined out of many deciders via combine function, a saga could be used to react on new events and send new commands to the decider recursively, in single transaction. It is using a EventRepository to fetch the current events and to save the new events. Generic parameters:

  • C - Command
  • S - State
  • E - Event
  • Repository - Event repository
  • Version - Version/Offset/Sequence number
  • Error - Error

Implementations§

Source§

impl<'a, C, S, E, Repository, Version, Error> EventSourcedOrchestratingAggregate<'a, C, S, E, Repository, Version, Error>
where Repository: EventRepository<C, E, Version, Error> + Sync, C: Sync, S: Sync, E: Sync + Clone, Version: Sync, Error: Sync,

Source

pub fn new( repository: Repository, decider: Decider<'a, C, S, E, Error>, saga: Saga<'a, E, C>, ) -> Self

Creates a new instance of EventSourcedAggregate.

Source

pub async fn handle(&self, command: &C) -> Result<Vec<(E, Version)>, Error>
where E: Identifier, C: Identifier,

Handles the command by fetching the events from the repository, computing new events based on the current events and the command, and saving the new events to the repository.

Trait Implementations§

Source§

impl<C, S, E, Repository, Version, Error> EventRepository<C, E, Version, Error> for EventSourcedOrchestratingAggregate<'_, C, S, E, Repository, Version, Error>
where Repository: EventRepository<C, E, Version, Error> + Sync, C: Sync, S: Sync, E: Sync, Version: Sync, Error: Sync,

Source§

async fn fetch_events(&self, command: &C) -> Result<Vec<(E, Version)>, Error>

Fetches current events, based on the command.

Source§

async fn save(&self, events: &[E]) -> Result<Vec<(E, Version)>, Error>

Saves events.

Source§

async fn version_provider(&self, event: &E) -> Result<Option<Version>, Error>

Version provider. It is used to provide the version/sequence of the event. Optimistic locking is useing this version to check if the event is already saved.

Auto Trait Implementations§

§

impl<'a, C, S, E, Repository, Version, Error> Freeze for EventSourcedOrchestratingAggregate<'a, C, S, E, Repository, Version, Error>
where Repository: Freeze,

§

impl<'a, C, S, E, Repository, Version, Error> !RefUnwindSafe for EventSourcedOrchestratingAggregate<'a, C, S, E, Repository, Version, Error>

§

impl<'a, C, S, E, Repository, Version, Error> Send for EventSourcedOrchestratingAggregate<'a, C, S, E, Repository, Version, Error>
where Repository: Send, C: Send, S: Send, E: Send, Version: Send, Error: Send,

§

impl<'a, C, S, E, Repository, Version, Error> Sync for EventSourcedOrchestratingAggregate<'a, C, S, E, Repository, Version, Error>
where Repository: Sync, C: Sync, S: Sync, E: Sync, Version: Sync, Error: Sync,

§

impl<'a, C, S, E, Repository, Version, Error> Unpin for EventSourcedOrchestratingAggregate<'a, C, S, E, Repository, Version, Error>
where Repository: Unpin, C: Unpin, S: Unpin, E: Unpin, Version: Unpin, Error: Unpin,

§

impl<'a, C, S, E, Repository, Version, Error> !UnwindSafe for EventSourcedOrchestratingAggregate<'a, C, S, E, Repository, Version, Error>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.