Class ModifiableAggregateRoot<T>

java.lang.Object
io.fluxzero.sdk.modeling.DelegatingEntity<T>
io.fluxzero.sdk.modeling.ModifiableAggregateRoot<T>
Type Parameters:
T - the type of the aggregate's value.
All Implemented Interfaces:
AggregateRoot<T>, Entity<T>

public class ModifiableAggregateRoot<T> extends DelegatingEntity<T> implements AggregateRoot<T>
A mutable, stateful AggregateRoot implementation that allows in-place updates and applies events with commit support for persisting the state and synchronizing it with the Fluxzero Runtime.

This class acts as a wrapper around an immutable entity (typically an ImmutableAggregateRoot), providing additional lifecycle management for:

  • Capturing uncommitted changes during an event or command handler execution.
  • Intercepting and applying updates and events with legality assertions.
  • Buffering applied events and committing them via a ModifiableAggregateRoot.CommitHandler callback.
  • Supporting batch-commit semantics for grouped event processing.
  • Tracking active aggregates for correlation and relationship resolution during handlers.

Commit Lifecycle

During handler invocation, intercepted updates and applied events are stored in a temporary buffer. When the handler completes successfully, events are committed via the configured ModifiableAggregateRoot.CommitHandler, which typically stores events in the EventStore and publishes them if needed.

If the handler fails (throws), state changes and captured events are discarded, and the aggregate is rolled back to the last stable state.

Publication Strategy

Events are published according to the EventPublication and EventPublicationStrategy specified either globally or on individual Apply-annotated methods. This allows fine-grained control over which events are stored or published.

Execution-Scoped Aggregates

All active ModifiableAggregateRoot instances are tracked per thread and aggregate repository, enabling relationship resolution and update tracking across aggregates within the same handler context while isolating nested or interleaved repository executions.

This mechanism enables other parts of the framework to determine which aggregates are currently in use or updated within a processing thread, without requiring external state.

See Also: