Hey is anyone aware of a KMP DI or ViewModel libra...
# multiplatform
a
Hey is anyone aware of a KMP DI or ViewModel library that provides a cross platform version of the
hiltViewModels()
method in Android?
x
I know that Koin has the
koinViewModel()
function. Not sure if it behaves the same way as the
hiltViewModels()
does though, as I haven’t tried it out myself
a
Thanks!
a
Hah, this is likely even better since it covers nav too!
x
Nice one @Emre!
a
@Emre how does that integrate with DI on the iOS side of things?
Since hilt DI would only be on the Android side right?
x
Since hilt DI would only be on the Android side right?
Yes, it ought to be, as Hilt is not yet migrated to KSP (see KSP supported libraries). I’m curious to know how Voyager approaches this
e
No se, ‘coz I use Koin for cross-platform DI. The sample application voyager provides with Hilt is also Android only.
a
Update: Koject does exactly what I was hoping it would:
Copy code
fun MainContents(
    viewModel: MainViewModel = rememberInject()
) {
    var showImage by remember { mutableStateOf(false) }
    val state by viewModel.list.collectAsState()

    val navigator = LocalNavigator.currentOrThrow

    Column(
        modifier = Modifier.fillMaxSize(),
        horizontalAlignment = Alignment.CenterHorizontally
    ) {
    }
}
🙌 1
It even integrates very well with Voyager @Emre
👍 1
e
Nice! I had not heard of Koject. How did you pick it?
@Mori Atsushi What are the benefits of Koject over the libraries (like Koin) it is inspired by?
m