InsertKoinIO / koin

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

Ktor 3.0 support #1716

Open lexa-diky opened 11 months ago

lexa-diky commented 11 months ago

Is your feature request related to a problem? Please describe. JB recently released Ktor 3.0.0-betta1. Currently Ktor does not support it, JB changed API. In particular access to monitor now done via Application not Environment, maybe there is more incompatibilities.

Describe the solution you'd like Separate ktor-3 module to have both ktor 2. and 3.

Target Koin project ktor

Nek-12 commented 11 months ago

Can second this, but I would prefer a simple dependency upgrade instead of separate artifact

Nek-12 commented 11 months ago

The workaround for now is to copy everything from the koin Ktor sources and fix the compile time error

lexa-diky commented 11 months ago

If koin goes with single module approach, it will break comp with ktor-2, and I guess bunch of people will not update for a while

Nek-12 commented 11 months ago

The only updates for the past months have been dependency updates... The whole library is 2 files

arnaudgiuliani commented 11 months ago

Yes, great topic coming 👍

Nek-12 commented 10 months ago

Can you please add ktor 3.0 support first before you refactor, add new stuff, and break something with the update you described in your article? @arnaudgiuliani

Changing one line of code, that is, so that we don't wait till Q4 2024 for this to get fixed

arnaudgiuliani commented 9 months ago

something I can setup for 3.6.0 - Q1 Seems that we need to separate both ktor & ktor3

FlyingYu-Z commented 6 months ago

Is there any solution now?

JoonasC commented 4 months ago

@arnaudgiuliani I would appreciate a solution for this, as I am currently unable to use SSE (server sent events) in my application due to it only being supported in Ktor 3.0.0. Let me know if I can speed up the work, maybe by making a PR?

fluxxion82 commented 3 months ago

I'm am interested in this as well and will be watching for updates.

Nek-12 commented 3 months ago

@fluxxion82 Just copy all sources of the Ktor module to your project. This hasn't been addressed in almost a year and the author has no intention of doing so.

KevinMeneses commented 3 months ago

it would be nice to get support for this

hashir1296 commented 2 months ago

Still waiting for this. No solutions of as of yet?

Nek-12 commented 2 months ago

Like I said, just copy and paste all sources of Koin-ktor module into your project and fix the breaking changes. Already using this approach in prod

hashir1296 commented 2 months ago

Like I said, just copy and paste all sources of Koin-ktor module into your project and fix the breaking changes. Already using this approach in prod

Pardon but can you please briefly describe what do you mean by this? Earlier we were using koin as:

install(Koin) {
        slf4jLogger()
        modules(appModule)
    }

How do i migrate from this?

hashir1296 commented 2 months ago

Like I said, just copy and paste all sources of Koin-ktor module into your project and fix the breaking changes. Already using this approach in prod

Pardon but can you please briefly describe what do you mean by this? Earlier we were using koin as:

install(Koin) {
        slf4jLogger()
        modules(appModule)
    }

How do i migrate from this?

Figured it out, basically

  1. Goto this link: https://github.com/InsertKoinIO/koin/tree/main/projects/ktor/koin-ktor
  2. Manually copy/paste all files under koin-ktor package (I copied only KoinPlugin)
  3. In your install block, use your koin plugin instead of ktor's

Warning: This is a workaround, with this:

  1. You will lose out on future Ktor or Koin updates
  2. You’ll need to keep an eye on both the Koin and Ktor projects for official updates that may render this workaround obsolete.
chrisjenx commented 1 month ago

Yeah this is now broken on ktor 3.x:

java.lang.IncompatibleClassChangeError: Found interface io.ktor.server.routing.Routing, but class was expected
    at org.koin.ktor.ext.RoutingExtKt.getKoin(RoutingExt.kt:74)

Will need a ktor3 package, really the impl is basically the same, but they are incompatible due to changes to classes in ktor3

chrisjenx commented 1 month ago

PR here: https://github.com/InsertKoinIO/koin/pull/1978

There is jar with the ktor3 target if you need it for now

chrisjenx commented 1 month ago

@arnaudgiuliani if no objections, can we fast track to 4.0? Happy to maintain the module if you ping me. (And get in the next RC?)

valeriyo commented 4 weeks ago

Ktor 3.0.0 has been released yesterday -- https://github.com/ktorio/ktor/releases/tag/3.0.0

It would be lovely if Koin supported it officially ❤️

arnaudgiuliani commented 3 weeks ago

I could open track for 4.1 in beta version, to play with this yes 👍 4.0 is in maintenance mode (no more features).

BierDav commented 3 weeks ago

Would really appreciate 🫶

sausti commented 2 weeks ago

I could open track for 4.1 in beta version, to play with this yes 👍 4.0 is in maintenance mode (no more features).

That would be a huge help!

Ynnck123 commented 2 weeks ago

@arnaudgiuliani can you by any chance give an estimated date when such a Beta version with Ktor 3.0.0 support will be testable for us? I'm really looking forward to it

batesjernigan-taxa commented 2 weeks ago

Bumping this. I tried using kodeine also instead of koin to see if the support was there and I ran into the same error mentioned above.

java.lang.IncompatibleClassChangeError: Found interface io.ktor.server.routing.Routing, but class was expected
jsixface commented 2 weeks ago

Bumping this. I tried using kodeine also instead of koin to see if the support was there and I ran into the same error mentioned above.

java.lang.IncompatibleClassChangeError: Found interface io.ktor.server.routing.Routing, but class was expected

If you try to inject outside of routing in Application scope, it might work.

batesjernigan-taxa commented 1 week ago

Bumping this. I tried using kodeine also instead of koin to see if the support was there and I ran into the same error mentioned above.

java.lang.IncompatibleClassChangeError: Found interface io.ktor.server.routing.Routing, but class was expected

If you try to inject outside of routing in Application scope, it might work.

@jsixface That actually worked for me! My update was to move the controller injection code out of the routing block. Thank you for the suggestion!

fun Application.configureRouting() {
    val fooController by inject<FooController>()
    routing {
        route("/foo") {
            get {            
                // ...
            }
        }
    }
}

this was the incorrect code I had before

fun Application.configureRouting() {
    routing {
        route("/foo") {
            get {
                val fooController by inject<FooController>()
                // ...
            }
        }
    }
}
jsixface commented 1 week ago

You're welcome. Well, your code was not wrong in the first place. It's just that the KTOR 3.0 has some breaking changes and Koin 4.0 hasn't caught up with it.

Galarzaa90 commented 1 week ago

Damn, I had just changed all my "controller" files from Application extensions to Routing extensions :(

Wavesonics commented 6 days ago

ooph, open for almost a year 😟 has there been any progress on this?

Any work arounds?

chrisjenx commented 6 days ago

I posted a jar you can use, also it's super easy to just copy the plugin code and point at ktor3, there are really only 2 like changes. But yeah I have an open PR to merge in workings, dunno if @arnaudgiuliani needs me to do anything?

Jofairden commented 11 hours ago

Any update on the fix?