I have a confusion regarding ViewModel scopes I h...
# koin
p
I have a confusion regarding ViewModel scopes I have several Fragments and each of them have their own ViewModel. My module look like this
Copy code
module {
    viewModel { ... }
    ...
}
My question is that whether the ViewModel is automatically scoped to the lifecycle of Fragment or not? If not, then do I need to scope ViewModel to the Fragment like this?
Copy code
module {
    scope<MyFragment> {
         viewModel { ... }
    }
}
v
when viewmodel is injected into the fragment with koin, it is scoped to the fragment. If the fragment is destroyed so is the viewmodel
You can test this yourself, by setting a breakpoint in
onCleared
function of the viewmodel and check that it is called when the fragment is destroyed
p
Thanks, I'll test