onSourcing

open override fun onSourcing(eventStream: DomainEventStream): StateAggregate<S>

Applies a stream of domain events to update the aggregate's state.

The stream is checked first (aggregate ID, next version). Then every event is applied to the state: the user's sourcing functions run, and the framework's system events (delete, recover, owner, space, tags) are noted. Only after all of them succeeded does the aggregate take the stream's version, event ID, operator, time and the noted metadata. When a sourcing function throws, the aggregate's metadata stays at the previous version; the state object may hold part of the stream and must be discarded.

Return

This aggregate instance after sourcing.

Parameters

eventStream

The domain event stream to source from.

Throws

If the aggregate ID does not match the event stream's aggregate ID.

If the expected next version does not match the event stream's version.

Example usage:

val aggregate = SimpleStateAggregate(...)
val eventStream = DomainEventStream(...)
aggregate.onSourcing(eventStream)