It took a bit of experimentation to integrate <#C6...
# tornadofx
i
It took a bit of experimentation to integrate #koin with TornadoFX for DI since `DIContainer.getInstance()`'s type parameter is not reified, and Koin's usual
KoinComponent.get()
expects the type to be known at the call site. It turns out Koin does have lesser documented
get()
API via
KoinComponent.getKoin()
that isn't inlined and takes a
KClass
. If anyone is interested, here is how I got it to work:
Copy code
FX.dicontainer = object : DIContainer, KoinComponent {
	override fun <T : Any> getInstance(type: KClass<T>): T {
		return getKoin().get(clazz = type, qualifier = null, parameters = null)
	}
}
Full example here: https://github.com/ianbrandt/tornadofx-test/blob/ef59dc55d33e1d28602b0dcf939bd8f5811fb53d/koin/src/main/kotlin/com/ianbrandt/tornadofx/koin/KoinApp.kt