InsertKoinIO / koin

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

Ktor: Call stopKoin when Ktor application is shutting down #1892

Closed jacekgajek closed 3 weeks ago

jacekgajek commented 3 weeks ago

Currently we cannot properly/gracefully close resources because Ktor plugins does not execute onClose callbacks.

Workaround

fun Application.configureKoin() {
    install(Koin) {
        // define modules
    }

    // Workaround
    this.install(createApplicationPlugin("StopKoin") {
        on(MonitoringEvent(ApplicationStopPreparing)) {
            stopKoin()
        }
    })
}

I'm using version 3.5.6

jacekgajek commented 3 weeks ago

After removing the workaround it still works so this is a false issue. I'm closing it.