add function subscribeToBus to RepositoryInMemory

This commit is contained in:
2025-04-05 02:14:42 +02:00
parent 5ef49c1585
commit aca655952e
2 changed files with 9 additions and 6 deletions

View File

@@ -17,8 +17,6 @@ import io.github.oshai.kotlinlogging.withLoggingContext
*/ */
class GameListRepositoryInMemory( class GameListRepositoryInMemory(
eventStore: GameEventStore, eventStore: GameEventStore,
projectionBus: GameProjectionBus,
eventBus: GameEventBus,
snapshotConfig: SnapshotConfig = SnapshotConfig(), snapshotConfig: SnapshotConfig = SnapshotConfig(),
) : GameListRepository { ) : GameListRepository {
private val projectionsSnapshot = private val projectionsSnapshot =
@@ -29,7 +27,11 @@ class GameListRepositoryInMemory(
initialStateBuilder = { aggregateId: GameId -> GameList(aggregateId) }, initialStateBuilder = { aggregateId: GameId -> GameList(aggregateId) },
) )
init { fun subscribeToBus(
projectionBus: GameProjectionBus,
eventBus: GameEventBus,
) {
// On new event was received, build snapshot and publish it to the projection bus
eventBus.subscribe { event -> eventBus.subscribe { event ->
withLoggingContext("event" to event.toString()) { withLoggingContext("event" to event.toString()) {
projectionsSnapshot projectionsSnapshot

View File

@@ -17,8 +17,6 @@ import io.github.oshai.kotlinlogging.withLoggingContext
*/ */
class GameStateRepositoryInMemory( class GameStateRepositoryInMemory(
eventStore: GameEventStore, eventStore: GameEventStore,
projectionBus: GameProjectionBus,
eventBus: GameEventBus,
snapshotConfig: SnapshotConfig = SnapshotConfig(), snapshotConfig: SnapshotConfig = SnapshotConfig(),
) : GameStateRepository { ) : GameStateRepository {
private val projectionsSnapshot = private val projectionsSnapshot =
@@ -29,7 +27,10 @@ class GameStateRepositoryInMemory(
initialStateBuilder = { aggregateId: GameId -> GameState(aggregateId) }, initialStateBuilder = { aggregateId: GameId -> GameState(aggregateId) },
) )
init { fun subscribeToBus(
projectionBus: GameProjectionBus,
eventBus: GameEventBus,
) {
// On new event was received, build snapshot and publish it to the projection bus // On new event was received, build snapshot and publish it to the projection bus
eventBus.subscribe { event -> eventBus.subscribe { event ->
withLoggingContext("event" to event.toString()) { withLoggingContext("event" to event.toString()) {