diff --git a/src/main/kotlin/eventDemo/business/command/GameCommandHandler.kt b/src/main/kotlin/eventDemo/business/command/GameCommandHandler.kt index 9449112..2a7cb73 100644 --- a/src/main/kotlin/eventDemo/business/command/GameCommandHandler.kt +++ b/src/main/kotlin/eventDemo/business/command/GameCommandHandler.kt @@ -27,8 +27,6 @@ class GameCommandHandler( private val commandStreamChannel: CommandStreamChannel, 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)() diff --git a/src/main/kotlin/eventDemo/configuration/business/ConfigureGameListener.kt b/src/main/kotlin/eventDemo/configuration/business/ConfigureGameListener.kt index 467ff5a..e1f1db9 100644 --- a/src/main/kotlin/eventDemo/configuration/business/ConfigureGameListener.kt +++ b/src/main/kotlin/eventDemo/configuration/business/ConfigureGameListener.kt @@ -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() .subscribeToBus(get(), get()) + + get() + .subscribeToBus(get()) } diff --git a/src/main/kotlin/eventDemo/configuration/injection/ConfigureDIBusiness.kt b/src/main/kotlin/eventDemo/configuration/injection/ConfigureDIBusiness.kt index c41885b..96b0306 100644 --- a/src/main/kotlin/eventDemo/configuration/injection/ConfigureDIBusiness.kt +++ b/src/main/kotlin/eventDemo/configuration/injection/ConfigureDIBusiness.kt @@ -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)