lc
09/23/2025, 2:25 PMBruce Hamilton
09/23/2025, 5:05 PMdependencies {
provide(MyImplementation::class)
provide(::MyImplementation)
}
From the resolver:
dependencies.create(MyImplemenation::class)
From configuration:
application:
dependencies:
- com.example.MyImplemenation
lc
09/23/2025, 10:03 PMBruce Hamilton
09/24/2025, 6:21 AMlc
09/24/2025, 6:52 AMBruce Hamilton
09/24/2025, 6:56 AMlc
09/24/2025, 8:57 AMfun main(args: Array<String>) = EngineMain.main(args)
fun Application.cfg(key: String, default: String = "") = environment.config.propertyOrNull(key)?.getString() ?: default
fun Application.module(testing: Boolean = false) = runBlocking {
val log = KotlinLogging.logger {}
val buildNumber = System.getenv("BUILD_NUMBER") ?: TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis()).toString()
log.info { "rut-bot build $buildNumber starting..." }
configureDependencies()
startRutbot()
}
Dependencies.kt
fun Application.configureDependencies() {
val app = this
dependencies {
provide<Boolean> { false } // Debug mode off by default
provide("user") { app.cfg("rutbot.user") }
provide<RutConnectService> { RutConnectService(app) }
provide<LocalState> { LocalState(app) }
provide<RutBot> { RutBot(app) }
}
}
RutConnectService.kt
class RutConnectService(private val application: Application) {
val log = KotlinLogging.logger("RutConnect")
private val user = runBlocking { application.dependencies.resolve<String>("user") }
lc
09/24/2025, 9:06 AMfun Application.configureDependencies() {
val rutModule = module {
single(named(Parameters.key)) { cfg("ktor.environment", "dev") }
single(named(Parameters.debug)) { cfg("ktor.environment.debug", "false").toBoolean() }
single<RutConnectService> { RutConnectService() }
single<UserService> { UserService() }
single<LocalState> { LocalState() }
single<TradeService> { TradeService() }
}
install(Koin) {
slf4jLogger()
modules(rutModule)
}
}
RutConnectService.kt
class RutConnectService: KoinComponent {
val log = KotlinLogging.logger("RutConnect")
private val localState: LocalState by inject()
private val tradeService: TradeService by inject()
private val userService: UserService by inject()
Bruce Hamilton
09/24/2025, 10:19 PMdependencies.provide(RutConnectService::class)
for providing then expose the properties in the constructor. This decouples your class from Ktor and it's DI as well.lc
09/26/2025, 5:09 AMprovide<String>("user") { "tester.bill" }
Bruce Hamilton
09/26/2025, 6:52 AM@Named("user")
annotation on the property. With the lambda config it's just a string arg on resolve like provide { MyService(resolve('user")) }