InsertKoinIO / koin

Koin - a pragmatic lightweight dependency injection framework for Kotlin & Kotlin Multiplatform
https://insert-koin.io
Apache License 2.0
9.09k stars 719 forks source link

Get error while injecting inside Route in ktor #2008

Closed mhdabbaghy closed 4 days ago

mhdabbaghy commented 1 month ago

Describe the bug In ktor when i want to inject a class inside my Route I'm getting exception:

Exception in thread "main" java.lang.NoClassDefFoundError: io/ktor/server/routing/RoutingKt at org.koin.ktor.ext.RouteExtKt.getKoin(RouteExt.kt:74)

Here is my code: ` fun Route.authRoutes() {

val authService: AuthService by inject()

route("/auth") {
    loginRoute(authService)
}

} `

but when I change code to

` fun Route.authRoutes() {

val authService: AuthService by application.inject()

route("/auth") {
    loginRoute(authService)
}

} ` It works fine

Koin version: 4.0.0 Ktor version: 3.0.0-rc-1 kotlin version: 2.0.20

octogene commented 1 month ago

As a workaround you can build or use the package from this PR : https://github.com/InsertKoinIO/koin/pull/1978 Tested on my project after a rebase on 4.0.0 and it works without problems.

Nek-12 commented 1 month ago

Duplicate of #1716

sschuberth commented 3 weeks ago

Duplicate of #1716

Indeed, please close this issue @mhdabbaghy.