From aca655952ee3521f49ead8a268fdfabc6168ab84 Mon Sep 17 00:00:00 2001 From: Fabrice Lecomte Date: Sat, 5 Apr 2025 02:14:42 +0200 Subject: [PATCH] add function subscribeToBus to RepositoryInMemory --- .../event/projection/GameListRepositoryInMemory.kt | 8 +++++--- .../event/projection/GameStateRepositoryInMemory.kt | 7 ++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/eventDemo/adapter/infrastructureLayer/event/projection/GameListRepositoryInMemory.kt b/src/main/kotlin/eventDemo/adapter/infrastructureLayer/event/projection/GameListRepositoryInMemory.kt index b1684e8..a5d06e4 100644 --- a/src/main/kotlin/eventDemo/adapter/infrastructureLayer/event/projection/GameListRepositoryInMemory.kt +++ b/src/main/kotlin/eventDemo/adapter/infrastructureLayer/event/projection/GameListRepositoryInMemory.kt @@ -17,8 +17,6 @@ import io.github.oshai.kotlinlogging.withLoggingContext */ class GameListRepositoryInMemory( eventStore: GameEventStore, - projectionBus: GameProjectionBus, - eventBus: GameEventBus, snapshotConfig: SnapshotConfig = SnapshotConfig(), ) : GameListRepository { private val projectionsSnapshot = @@ -29,7 +27,11 @@ class GameListRepositoryInMemory( 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 -> withLoggingContext("event" to event.toString()) { projectionsSnapshot diff --git a/src/main/kotlin/eventDemo/adapter/infrastructureLayer/event/projection/GameStateRepositoryInMemory.kt b/src/main/kotlin/eventDemo/adapter/infrastructureLayer/event/projection/GameStateRepositoryInMemory.kt index 1aedcc1..417714b 100644 --- a/src/main/kotlin/eventDemo/adapter/infrastructureLayer/event/projection/GameStateRepositoryInMemory.kt +++ b/src/main/kotlin/eventDemo/adapter/infrastructureLayer/event/projection/GameStateRepositoryInMemory.kt @@ -17,8 +17,6 @@ import io.github.oshai.kotlinlogging.withLoggingContext */ class GameStateRepositoryInMemory( eventStore: GameEventStore, - projectionBus: GameProjectionBus, - eventBus: GameEventBus, snapshotConfig: SnapshotConfig = SnapshotConfig(), ) : GameStateRepository { private val projectionsSnapshot = @@ -29,7 +27,10 @@ class GameStateRepositoryInMemory( 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 eventBus.subscribe { event -> withLoggingContext("event" to event.toString()) {