onSourcing

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

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

This method validates the event stream against the current aggregate state, applies each event to the state using registered sourcing functions, and updates metadata such as version and ownership.

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)