I'm trying to replace Dagger 2 to Koin in my current project and I don't want to rewrite some classes in Kotlin to use it.
Is possible to inject with Koin in java classes?
In Kotlin is just
// Inject MyPresenter
val presenter : MyPresenter by inject()
Thanks
Yeah, they work.
As I mentioned before Dagger/Hilt has a significant impact on build time due to code generation. On the other hand, Koin also affects time, but not build, but runtime. Koin has slightly worse runtime performance, because it resolves dependencies at runtime.
Koin is a popular and declarative library for DI, and it supports Kotlin Multiplatform. You declare the dependencies as modules, and Koin resolves them at runtime when needed.
Yes it is Possible. Just sync project with this gradle file
implementation "org.koin:koin-java:$koin_version"
In your java class replace
// Inject MyPresenter
private val presenter : MyPresenter by inject()
with
private Lazy<MyPresenter> presenter = inject(MyPresenter.class);
and get presenter method inside Java class like
presenter.getValue().sayHello()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With