Skip to content

Instantly share code, notes, and snippets.

@MarcusDunn
Created March 4, 2024 23:30
Show Gist options
  • Save MarcusDunn/d57e8875828ed980a2a37551d513a399 to your computer and use it in GitHub Desktop.
Save MarcusDunn/d57e8875828ed980a2a37551d513a399 to your computer and use it in GitHub Desktop.
import org.koin.dsl.bind
import org.koin.dsl.koinApplication
import org.koin.dsl.module
import kotlin.test.Test
import kotlin.test.fail
private fun module(useB: Boolean) = module {
single { AImpl() }
single { BAndAImpl() }
single { get<BAndAImpl>() } bind B::class
single {
if (useB) {
get<BAndAImpl>()
} else {
get<AImpl>()
}
} bind A::class
}
private interface A {
}
private interface B {
}
private class AImpl : A
private class BAndAImpl : A, B
class ReproStackOverflowTest {
@Test
fun stackOverflowTest() {
val koin = koinApplication {
modules(module(useB = false))
}
try {
koin.koin.get<A>()
koin.koin.get<B>()
} catch (e: Exception) {
fail(e.message)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment