https://kotlinlang.org logo
Title
m

Michal Klimczak

04/02/2022, 8:05 PM
I can't inject my class with koin when using ktor in development mode. (2.0.0-beta-1)
routing {
        val service by KoinJavaComponent.inject<PageService>(PageService::class.java)
...
Exception:
class com.xyz.PageService cannot be cast to class com.xyz.PageService (com.xyz.PageService is in unnamed module of loader 'app'; com.xyz.PageService is in unnamed module of loader io.ktor.server.engine.OverridingClassLoader$ChildURLClassLoader @55a88417)
Also it's injected fine at app startup, but fails with this exception when it's done in the
routing
lambda. Works fine when I disable development mode, too. Any ideas?
s

Sebastian Owodzin

04/03/2022, 5:55 PM
From what I can see Koin isn’t updated to plugin changes that were introduced in KTOR 2.0.0 (https://github.com/InsertKoinIO/koin/issues/1295)
:thank-you: 1
m

Michal Klimczak

04/04/2022, 6:13 AM
Thank you, to be honest I didn't even know I needed to install the ktor plugin at all, but it's indeed noted in the docs that it's required for the autoreload to work: https://insert-koin.io/docs/reference/koin-ktor/ktor/