mirland
09/17/2021, 3:21 PMarnaud.giuliani
09/20/2021, 9:56 AMviewModel
definition can be used inside a scope. It would allow you to reuse the same scoped
definition yes 👌mirland
09/20/2021, 8:58 PMclass CustomViewModel : ViewModel()
val module = module {
viewModel { CustomViewModel() }
}
@Composable
fun ViewModelComposable() {
val viewModelInstance = getViewModel<CustomViewModel>()
}
Using custom class:
class Foo
val module2 = module {
scope<> { // Not sure about the scope
scoped { Foo() }
}
}
@Composable
fun FooComposable() {
val foo = getKoin().get<Foo>()
}
So, what I need is that foo
has the same behavior as viewModelInstance
, they should have the same scope.
BTW: Keep in mind, that viewModel { ... }
definition can be used only if you extend a Jetpack View Model.
In my use case, I'm using Kotlin Multiplatform, I'm defining the view model in my shared module (Foo), and it cannot extend Jetpack's ViewModel. However, when I'm inject it from android, I need the same behavior as a Jetpack's ViewModelmirland
09/28/2021, 2:54 PMarnaud.giuliani
09/28/2021, 2:57 PMarnaud.giuliani
09/28/2021, 2:58 PMIn my use case, I’m using Kotlin Multiplatform, I’m defining the view model in my shared module (Foo), and it cannot extend Jetpack’s ViewModel. However, when I’m inject it from android, I need the same behavior as a Jetpack’s ViewModelthen in your case you can’t benefit from Android Scopes. You have to create/destroy scopes by hand, at the start and at the end of your main component
mirland
09/28/2021, 8:21 PM