Hi … I have a question about migration from koin 2...
# koin
c
Hi … I have a question about migration from koin 2.x to 3.x In my fragment I use something like this
val viewModel by getScope("user-session").viewModel<Class>(owner = this)
this works fine at least for koin 2.x. What happens in getscope() is it check it this scope is there or creates a new one of user-session. So that the viewmodel is bound to the user-session scope. For koin 3.x I have to add more complex implementation
val viewModel by getScope("user-session").viewModel<Class>(owner = {ViewModelOwner.from(findNavController().getViewModelStoreOwner(R.id.graph))})
is this the way to go or is there a better solution for ? Thanks in advance
a
from 3.1.3 scoping ViewModel is fixed. You will have access also to
koinNavGraphViewModel
to scope a ViewModel to a nav graph - https://insert-koin.io/docs/reference/koin-android/viewmodel#navigation-graph-viewmodel
c
Okay ... But in case I want to scope a viewModel to the custom scope for example a user- session which will be created after a login or something ? Thanks appreciate
a
not sure it’s a good idea to have a viewModel here, just use a
scoped
instance