connection to postgresql
This commit is contained in:
@@ -5,11 +5,18 @@ import org.koin.dsl.module
|
||||
fun appKoinModule(config: Configuration) =
|
||||
module {
|
||||
configureDIBusiness()
|
||||
configureDIInfrastructure(config.redisUrl)
|
||||
configureDIInfrastructure(config)
|
||||
configureDILibs()
|
||||
configureDICommandActions()
|
||||
}
|
||||
|
||||
data class Configuration(
|
||||
val redisUrl: String,
|
||||
)
|
||||
val postgresql: Postgresql,
|
||||
) {
|
||||
data class Postgresql(
|
||||
val url: String,
|
||||
val username: String,
|
||||
val password: String,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package eventDemo.configuration.injection
|
||||
|
||||
import com.zaxxer.hikari.HikariConfig
|
||||
import com.zaxxer.hikari.HikariDataSource
|
||||
import eventDemo.adapter.infrastructureLayer.event.GameEventBusInMemory
|
||||
import eventDemo.adapter.infrastructureLayer.event.GameEventStoreInMemory
|
||||
import eventDemo.adapter.infrastructureLayer.event.projection.GameListRepositoryInMemory
|
||||
@@ -16,12 +18,24 @@ import org.koin.core.module.dsl.singleOf
|
||||
import org.koin.dsl.bind
|
||||
import redis.clients.jedis.JedisPooled
|
||||
import redis.clients.jedis.UnifiedJedis
|
||||
import javax.sql.DataSource
|
||||
|
||||
fun Module.configureDIInfrastructure(redisUrl: String) {
|
||||
fun Module.configureDIInfrastructure(config: Configuration) {
|
||||
factory {
|
||||
JedisPooled(redisUrl)
|
||||
JedisPooled(config.redisUrl)
|
||||
} bind UnifiedJedis::class
|
||||
|
||||
single {
|
||||
HikariConfig()
|
||||
.apply {
|
||||
jdbcUrl = config.postgresql.url
|
||||
username = config.postgresql.username
|
||||
password = config.postgresql.password
|
||||
}.let {
|
||||
HikariDataSource(it)
|
||||
}
|
||||
} bind DataSource::class
|
||||
|
||||
singleOf(::GameEventBusInMemory) bind GameEventBus::class
|
||||
singleOf(::GameEventStoreInMemory) bind GameEventStore::class
|
||||
singleOf(::GameProjectionBusInMemory) bind GameProjectionBus::class
|
||||
|
||||
@@ -4,6 +4,7 @@ import eventDemo.configuration.injection.Configuration
|
||||
import eventDemo.configuration.injection.appKoinModule
|
||||
import io.ktor.server.application.Application
|
||||
import io.ktor.server.application.install
|
||||
import io.ktor.server.config.ApplicationConfig
|
||||
import org.koin.ktor.plugin.Koin
|
||||
import org.koin.logger.slf4jLogger
|
||||
|
||||
@@ -11,7 +12,24 @@ fun Application.configureKoin() {
|
||||
install(Koin) {
|
||||
slf4jLogger()
|
||||
|
||||
val redisUrl = environment.config.propertyOrNull("redis.url")?.getString() ?: error("You must set the redis.url")
|
||||
modules(appKoinModule(Configuration(redisUrl)))
|
||||
modules(
|
||||
appKoinModule(
|
||||
environment.config.configuration(),
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun ApplicationConfig.configuration() =
|
||||
Configuration(
|
||||
redisUrl = getProperty("redis.url"),
|
||||
postgresql =
|
||||
Configuration.Postgresql(
|
||||
url = getProperty("postgresql.url"),
|
||||
username = getProperty("postgresql.username"),
|
||||
password = getProperty("postgresql.password"),
|
||||
),
|
||||
)
|
||||
|
||||
private fun ApplicationConfig.getProperty(path: String): String =
|
||||
propertyOrNull(path)?.getString() ?: error("You must set the $path")
|
||||
|
||||
@@ -6,4 +6,15 @@ jwt {
|
||||
redis {
|
||||
url = "redis://localhost:6379"
|
||||
url = ${?REDIS_URL}
|
||||
}
|
||||
|
||||
postgresql {
|
||||
url = "jdbc:postgresql://localhost:5432/event-demo"
|
||||
url = ${?POSTGRESQL_URL}
|
||||
|
||||
username = "event-demo"
|
||||
username = ${?POSTGRESQL_USERNAME}
|
||||
|
||||
password = "changeit"
|
||||
password = ${?POSTGRESQL_PASSWORD}
|
||||
}
|
||||
Reference in New Issue
Block a user