create ProjectionSnapshotRepositoryInRedis
This commit is contained in:
@@ -11,15 +11,35 @@ import eventDemo.business.event.projection.GameProjectionBus
|
||||
import eventDemo.business.event.projection.gameList.GameListRepository
|
||||
import eventDemo.business.event.projection.gameState.GameStateRepository
|
||||
import eventDemo.libs.event.projection.SnapshotConfig
|
||||
import kotlinx.serialization.KSerializer
|
||||
import kotlinx.serialization.json.Json
|
||||
import kotlinx.serialization.serializer
|
||||
import org.koin.core.module.Module
|
||||
import org.koin.core.module.dsl.singleOf
|
||||
import org.koin.dsl.bind
|
||||
import redis.clients.jedis.JedisPooled
|
||||
import redis.clients.jedis.UnifiedJedis
|
||||
import redis.clients.jedis.json.JsonObjectMapper
|
||||
|
||||
fun Module.configureDIInfrastructure(redisUrl: String) {
|
||||
single {
|
||||
JedisPooled(redisUrl)
|
||||
}
|
||||
factory {
|
||||
JedisPooled(redisUrl).apply {
|
||||
setJsonObjectMapper(
|
||||
object : JsonObjectMapper {
|
||||
override fun <T> fromJson(
|
||||
value: String,
|
||||
valueType: Class<T>,
|
||||
): T {
|
||||
val s: KSerializer<T> = serializer(valueType) as KSerializer<T>
|
||||
return Json.decodeFromString(s, value)
|
||||
}
|
||||
|
||||
override fun toJson(value: Any): String =
|
||||
Json.encodeToString(value)
|
||||
},
|
||||
)
|
||||
}
|
||||
} bind UnifiedJedis::class
|
||||
|
||||
singleOf(::GameEventBusInMemory) bind GameEventBus::class
|
||||
singleOf(::GameEventStoreInMemory) bind GameEventStore::class
|
||||
|
||||
Reference in New Issue
Block a user