Skip to content

Commit

Permalink
Merge pull request #1797 from momosetkn/feat/ktor-auto-reload
Browse files Browse the repository at this point in the history
Fix for can auto-reload on ktor
  • Loading branch information
arnaudgiuliani committed Mar 29, 2024
2 parents 28c22a4 + e148626 commit 78d9e70
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ import io.ktor.server.application.hooks.*
import io.ktor.util.*
import org.koin.core.KoinApplication
import org.koin.core.context.startKoin
import org.koin.core.context.stopKoin
import org.koin.core.scope.Scope
import org.koin.dsl.KoinAppDeclaration
import org.koin.mp.KoinPlatformTools

/**
* @author Arnaud Giuliani
Expand All @@ -34,6 +36,7 @@ import org.koin.dsl.KoinAppDeclaration
*/
val Koin = createApplicationPlugin(name = "Koin", createConfiguration = { KoinApplication.init() }) {
val koinApplication = setupKoinApplication()
KoinPlatformTools.defaultContext().getOrNull()?.let { stopKoin() } // for ktor auto-reload
startKoin(koinApplication)
setupMonitoring(koinApplication)
setupKoinScope(koinApplication)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,29 @@ class KoinPluginRunTest {
s.stop()
assert(counter == 1){ "counter should 1 - instance is created" }
}

@Test
@Ignore // socket exception on GH
fun `should can reload`() = runBlocking<Unit> {
val koinModule = module {
single<String> {
"Reproduction test"
}
}
val s = embeddedServer(
Netty,
module = {
install(Koin) {
modules(koinModule)
}
},
).start(false)
delay(500)

// verify for can auto-reload
(s.environment as ApplicationEngineEnvironmentReloading).reload()
s.stop()
}
}

private fun testMyApplication(test: suspend (jsonClient: HttpClient) -> Unit) = testApplication {
Expand Down

0 comments on commit 78d9e70

Please sign in to comment.