add function subscribeToBus to RepositoryInMemory
This commit is contained in:
@@ -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
|
||||||
|
|||||||
@@ -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()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user