EventSourcingStateAggregateRepository

Repository for loading state aggregates using event sourcing. This repository reconstructs the current state of an aggregate by combining snapshots (if available) with event streams from the event store. It supports loading aggregates up to a specific version or event time, enabling point-in-time state reconstruction.

The loading process works as follows:

  1. If loading the latest version (tailVersion = Int.MAX_VALUE), attempt to load from snapshot first.

  2. If no snapshot exists, create a new aggregate instance.

  3. Apply events from the event store starting from the aggregate's expected next version.

Author

ahoo wang

Parameters

stateAggregateFactory

Factory for creating new state aggregate instances.

snapshotRepository

Repository for loading and storing aggregate snapshots.

eventStore

Store for retrieving event streams associated with aggregates.

Constructors

Link copied to clipboard
constructor(stateAggregateFactory: StateAggregateFactory, snapshotRepository: SnapshotRepository, eventStore: EventStore)

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
open override fun <S : Any> load(aggregateId: AggregateId, metadata: StateAggregateMetadata<S>, tailVersion: Int): Mono<StateAggregate<S>>

Loads a state aggregate by its ID up to a specified version.

open override fun <S : Any> load(aggregateId: AggregateId, metadata: StateAggregateMetadata<S>, tailEventTime: Long): Mono<StateAggregate<S>>

Loads a state aggregate by its ID up to a specified event time.