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§
Sourcetype Event: Message + Send + Sync + Clone
type Event: Message + Send + Sync + Clone
The type of Domain Events that interest this Aggregate.
Usually, this type should be an enum
.
Sourcetype Error: Send + Sync
type Error: Send + Sync
The error type that can be returned by Aggregate::apply
when
mutating the Aggregate state.
Required Methods§
Sourcefn aggregate_id(&self) -> &Self::Id
fn aggregate_id(&self) -> &Self::Id
Returns the unique identifier for the Aggregate instance.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.