Hi i have been messing around with alternatives to...
# multiplatform
m
Hi i have been messing around with alternatives to Koin and Kodein for dependency injection. Im looking for a compile time dependency injection where it is possible to inject into viewmodels and use them in the Composable screens. I used dagger/hilt previously but since it is Android only i cant use it in CMP projects. Is there a way to “make” hilt suitable for CMP projects?
🚫 1
c
No, because dagger is generating Java code.
m
I interpret this as it could be used with KSP and thereby generating kotlin code https://dagger.dev/dev-guide/ksp.html
c
hilt might generate kotlin code but dagger in the end is a java library that is generating java code.
m
So if i understand this correctly my generated classes would be in kotlin but the library that reads these classes (provide my viewmodels to the screen) is in java and therefore do not work in KMP
c
no, dagger/hilt is a “code generator” that is generating java code that is compiled with you application. Hilt is just taking away writing boilerplate code for your android application so you can inject you modules easily into your android components.
👌 1
Dependency Injection per se is just a programming style, you don’t need a libaray for it.
2
m
Thats true, but i like it.
c
sure, it’s convenient 🙂
s
Kotlin Inject https://github.com/evant/kotlin-inject has compile time checks, but I don't think it supports Hilt-like features for ViewModels and such.
1
m
Hey Koin had introduced Anontation processors recently, i think you can have a look at it.https://insert-koin.io/docs/setup/annotations