diff --git a/src/main/kotlin/eventDemo/configuration/injection/ConfigureDI.kt b/src/main/kotlin/eventDemo/configuration/injection/ConfigureDI.kt index e03a1ab..4f9495d 100644 --- a/src/main/kotlin/eventDemo/configuration/injection/ConfigureDI.kt +++ b/src/main/kotlin/eventDemo/configuration/injection/ConfigureDI.kt @@ -2,10 +2,14 @@ package eventDemo.configuration.injection import org.koin.dsl.module -val appKoinModule = +fun appKoinModule(config: Configuration) = module { configureDIBusiness() - configureDIInfrastructure() + configureDIInfrastructure(config.redisUrl) configureDILibs() configureDICommandActions() } + +data class Configuration( + val redisUrl: String, +) diff --git a/src/main/kotlin/eventDemo/configuration/injection/ConfigureDIInfrastructure.kt b/src/main/kotlin/eventDemo/configuration/injection/ConfigureDIInfrastructure.kt index 53050b8..cca364e 100644 --- a/src/main/kotlin/eventDemo/configuration/injection/ConfigureDIInfrastructure.kt +++ b/src/main/kotlin/eventDemo/configuration/injection/ConfigureDIInfrastructure.kt @@ -14,8 +14,13 @@ import eventDemo.libs.event.projection.SnapshotConfig import org.koin.core.module.Module import org.koin.core.module.dsl.singleOf import org.koin.dsl.bind +import redis.clients.jedis.JedisPool + +fun Module.configureDIInfrastructure(redisUrl: String) { + single { + JedisPool(redisUrl) + } -fun Module.configureDIInfrastructure() { singleOf(::GameEventBusInMemory) bind GameEventBus::class singleOf(::GameEventStoreInMemory) bind GameEventStore::class singleOf(::GameProjectionBusInMemory) bind GameProjectionBus::class diff --git a/src/main/kotlin/eventDemo/configuration/ktor/ConfigureKoin.kt b/src/main/kotlin/eventDemo/configuration/ktor/ConfigureKoin.kt index 91912d9..24d9d31 100644 --- a/src/main/kotlin/eventDemo/configuration/ktor/ConfigureKoin.kt +++ b/src/main/kotlin/eventDemo/configuration/ktor/ConfigureKoin.kt @@ -1,5 +1,6 @@ package eventDemo.configuration.ktor +import eventDemo.configuration.injection.Configuration import eventDemo.configuration.injection.appKoinModule import io.ktor.server.application.Application import io.ktor.server.application.install @@ -9,6 +10,8 @@ import org.koin.logger.slf4jLogger fun Application.configureKoin() { install(Koin) { slf4jLogger() - modules(appKoinModule) + + val redisUrl = environment.config.propertyOrNull("redis.url")?.getString() ?: error("You must set the redis.url") + modules(appKoinModule(Configuration(redisUrl))) } } diff --git a/src/main/resources/application.conf b/src/main/resources/application.conf index 2bc624d..c30e5ff 100644 --- a/src/main/resources/application.conf +++ b/src/main/resources/application.conf @@ -1,4 +1,9 @@ jwt { secret = "secret" secret = ${?JWT_SECRET} +} + +redis { + url = "redis://localhost:6379" + url = ${?REDIS_URL} } \ No newline at end of file diff --git a/src/test/kotlin/eventDemo/adapter/interfaceLayer/query/GameSimulationTest.kt b/src/test/kotlin/eventDemo/adapter/interfaceLayer/query/GameSimulationTest.kt index c7b1a56..3749b16 100644 --- a/src/test/kotlin/eventDemo/adapter/interfaceLayer/query/GameSimulationTest.kt +++ b/src/test/kotlin/eventDemo/adapter/interfaceLayer/query/GameSimulationTest.kt @@ -27,6 +27,7 @@ import eventDemo.libs.event.projection.ProjectionSnapshotRepositoryInMemory import io.kotest.core.spec.style.FunSpec import io.kotest.matchers.collections.shouldHaveSize import io.kotest.matchers.equals.shouldBeEqual +import io.mockk.mockk import kotlinx.coroutines.DelicateCoroutinesApi import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.GlobalScope @@ -170,7 +171,7 @@ class GameSimulationTest : } } - koinApplication { modules(appKoinModule) }.koin.apply { + koinApplication { modules(appKoinModule(mockk(relaxed = true))) }.koin.apply { val commandHandler by inject() val eventStore by inject() val playerNotificationListener by inject() diff --git a/src/test/kotlin/eventDemo/business/command/GameCommandHandlerTest.kt b/src/test/kotlin/eventDemo/business/command/GameCommandHandlerTest.kt index 714ca27..58105a6 100644 --- a/src/test/kotlin/eventDemo/business/command/GameCommandHandlerTest.kt +++ b/src/test/kotlin/eventDemo/business/command/GameCommandHandlerTest.kt @@ -13,6 +13,7 @@ import eventDemo.configuration.injection.appKoinModule import io.kotest.core.spec.style.FunSpec import io.kotest.matchers.collections.shouldContain import io.kotest.matchers.equals.shouldBeEqual +import io.mockk.mockk import kotlinx.coroutines.DelicateCoroutinesApi import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.channels.Channel @@ -25,7 +26,7 @@ import kotlin.test.assertIs class GameCommandHandlerTest : FunSpec({ test("handle a command should execute the command") { - koinApplication { modules(appKoinModule) }.koin.apply { + koinApplication { modules(appKoinModule(mockk(relaxed = true))) }.koin.apply { val commandHandler by inject() val notificationListener by inject() val gameId = GameId() diff --git a/src/test/kotlin/eventDemo/business/event/projection/GameStateRepositoryTest.kt b/src/test/kotlin/eventDemo/business/event/projection/GameStateRepositoryTest.kt index 51be241..587bac5 100644 --- a/src/test/kotlin/eventDemo/business/event/projection/GameStateRepositoryTest.kt +++ b/src/test/kotlin/eventDemo/business/event/projection/GameStateRepositoryTest.kt @@ -9,6 +9,7 @@ import eventDemo.configuration.injection.appKoinModule import io.kotest.core.spec.style.FunSpec import io.kotest.matchers.collections.shouldHaveSize import io.kotest.matchers.equals.shouldBeEqual +import io.mockk.mockk import kotlinx.coroutines.DelicateCoroutinesApi import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.joinAll @@ -25,7 +26,7 @@ class GameStateRepositoryTest : test("GameStateRepository should build the projection when a new event occurs") { val aggregateId = GameId() - koinApplication { modules(appKoinModule) }.koin.apply { + koinApplication { modules(appKoinModule(mockk(relaxed = true))) }.koin.apply { val repo = get() val eventHandler = get() eventHandler @@ -44,7 +45,7 @@ class GameStateRepositoryTest : test("get should build the last version of the state") { val aggregateId = GameId() - koinApplication { modules(appKoinModule) }.koin.apply { + koinApplication { modules(appKoinModule(mockk(relaxed = true))) }.koin.apply { val repo = get() val eventHandler = get() @@ -69,7 +70,7 @@ class GameStateRepositoryTest : test("getUntil should build the state until the event") { repeat(10) { val aggregateId = GameId() - koinApplication { modules(appKoinModule) }.koin.apply { + koinApplication { modules(appKoinModule(mockk(relaxed = true))) }.koin.apply { val repo = get() val eventHandler = get() @@ -98,7 +99,7 @@ class GameStateRepositoryTest : test("getUntil should be concurrently secure") { val aggregateId = GameId() - koinApplication { modules(appKoinModule) }.koin.apply { + koinApplication { modules(appKoinModule(mockk(relaxed = true))) }.koin.apply { val repo = get() val eventHandler = get()