add function subscribeToBus to GameCommandHandler

This commit is contained in:
2025-04-05 03:00:32 +02:00
parent 903eb975e3
commit e1529ee52c
3 changed files with 9 additions and 4 deletions

View File

@@ -27,8 +27,6 @@ class GameCommandHandler(
private val commandStreamChannel: CommandStreamChannel<GameCommand>,
private val eventHandler: GameEventHandler,
private val runner: GameCommandActionRunner,
eventBus: GameEventBus,
listenerPriority: Int = DEFAULT_PRIORITY,
) {
private val logger = KotlinLogging.logger { }
private val eventCommandMap = EventCommandMap()
@@ -38,7 +36,10 @@ class GameCommandHandler(
}
// subscribe to the event bus to send success notification after save the event.
init {
fun subscribeToBus(
eventBus: GameEventBus,
listenerPriority: Int = DEFAULT_PRIORITY,
) {
eventBus.subscribe(listenerPriority) { event: GameEvent ->
eventCommandMap[event.eventId]?.apply {
channel.sendSuccess(commandId)()

View File

@@ -2,6 +2,7 @@ package eventDemo.configuration.business
import eventDemo.adapter.infrastructureLayer.event.projection.GameListRepositoryInMemory
import eventDemo.adapter.infrastructureLayer.event.projection.GameStateRepositoryInMemory
import eventDemo.business.command.GameCommandHandler
import eventDemo.business.event.projection.projectionListener.ReactionListener
import org.koin.core.Koin
@@ -14,4 +15,7 @@ fun Koin.configureGameListener() {
get<GameListRepositoryInMemory>()
.subscribeToBus(get(), get())
get<GameCommandHandler>()
.subscribeToBus(get())
}

View File

@@ -10,7 +10,7 @@ import org.koin.core.module.dsl.singleOf
fun Module.configureDIBusiness() {
single {
GameCommandHandler(get(), get(), get(), get())
GameCommandHandler(get(), get(), get())
}
singleOf(::GameEventHandler)
singleOf(::GameCommandActionRunner)