Platform compatibility & Genericity
Kodein-DI 7.6.0 is built upon and compatible with Kotlin 1.5.0. Also, it requires at least JDK 1.8, for JVM projects. |
Kodein-DI is compatible with all platforms that the Kotlin language compiles to: JVM & compatible (Android), Javascript and all the Kotlin/Native targets.
Since 7.0.0
, a new type system has been designed and included to Kodein-DI.
Thus, it appears to the developer that there is no more obvious differences between platforms, you no longer have to choose between erased
or generic
dependencies.
Starting from 7.0.0
, Kodein-DI is using the generic
version of the type system, meaning you should be able to bind generics easily for Kotlin/Multiplatform projects.
So, whatever platform you are targeting, bind<List<String>>()
and bind<List<Int>>()
will represent two different bindings.
Similarly, di.instance<List<String>>()
and di.instance<List<Int>>()
will yield two different list.
Since 7.0, Kodein-DI can use |
The JVM case
However, you should be aware that under the hood, this new type system uses the new function typeOf()
from Kotlin, for every platforms, except for the JVM that still have it’s own generic
implementation.
Meaning that the JVM counterpart of the type system makes a heavy use of reflection, so it’s less optimized.
Yes, #perfmatters. However, the humble opinion of the author is that:
Therefore, please make sure that, using the erased version is right for your use case, before blindly using it ;). Do profile your code! |
Even if by default Kodein-DI uses a generic type system, you still can use the erased one manually.
|