pub trait AggregateRoot: PersistentEntity {
type Event: Send + Sync + Clone;
// Required methods
fn uncommitted_events(&self) -> &[Self::Event];
fn clear_events(&mut self);
fn apply_event(&mut self, event: Self::Event);
// Provided methods
fn version(&self) -> Option<u64> { ... }
fn increment_version(&mut self) { ... }
fn has_uncommitted_events(&self) -> bool { ... }
fn uncommitted_event_count(&self) -> usize { ... }
}Expand description
DDD Aggregate Root trait.
Aggregate Roots are characterized by:
- Being the only entry point to the aggregate
- Maintaining consistency boundaries
- Publishing domain events for state changes
- Having a unique identity (via
PersistentEntity)
Required Associated Types§
Required Methods§
Sourcefn uncommitted_events(&self) -> &[Self::Event]
fn uncommitted_events(&self) -> &[Self::Event]
Get all uncommitted domain events.
These events should be persisted/published after the aggregate is saved to the repository.
Sourcefn clear_events(&mut self)
fn clear_events(&mut self)
Clear all uncommitted events.
This should be called after events have been persisted/published.
Sourcefn apply_event(&mut self, event: Self::Event)
fn apply_event(&mut self, event: Self::Event)
Apply a domain event to update the aggregate state.
This method should:
- Update the aggregate’s internal state based on the event
- Store the event in the uncommitted events list
Provided Methods§
Sourcefn version(&self) -> Option<u64>
fn version(&self) -> Option<u64>
Get the aggregate version for optimistic concurrency.
Returns None if versioning is not supported.
Sourcefn increment_version(&mut self)
fn increment_version(&mut self)
Increment the aggregate version.
Called after successful persistence.
Sourcefn has_uncommitted_events(&self) -> bool
fn has_uncommitted_events(&self) -> bool
Check if there are any uncommitted events.
Sourcefn uncommitted_event_count(&self) -> usize
fn uncommitted_event_count(&self) -> usize
Get the number of uncommitted events.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".