mori-atsushi / koject

DI Container library for Kotlin Multiplatform.
https://mori-atsushi.github.io/koject/
Apache License 2.0
122 stars 3 forks source link

viewmodel for compose multiplatform #290

Closed mahramane closed 6 months ago

mahramane commented 1 year ago

Hi Is it possible to make a viewmodel that can be used for compose multiplatform and also be available using injectViewModel() inside composable functions?

ColtonIdle commented 1 year ago

yeah. interested in this as well. Maybe a better route would be... @mori-atsushi do you know if this can support precomposes viewmodel (since that is kmp compatible?)

mori-atsushi commented 1 year ago

injectViewModel is for Android ViewModel, it cannot be used with KMP.

precomposes viewmodel

I'm not familiar with precompose ViewModel, but the following might work.

@Provides
class SomeViewModel(
    val repository: SomeRepository
) : ViewModel() {
    /* ... */
}
val viewModel = viewModel { inject<SomeViewModel>() }