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(
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

View File

@@ -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()) {