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