activity.getViewModel(named("XXX")) is returning wrong viewmodel after Koin 3.1.5 #1364
Labels
android:viewmodel
android
regression 💥
status:checking
currently in analysis - discussion or need more detailed specs
type:issue
Milestone
So I tried updating to 3.2.0 from Koin 2.x and I found an obscure bug. I reverted to lower versions until the problem was no longer present, which is version 3.1.5. Meaning the bug was introduced in 3.1.6.
I have two subtypes of an abstract viewModel that are scoped to my MainActivity. I first load the first type using a named qualifier (using the extension function activity.getViewModel() - This is from a non activity or fragment class. But after this, I try getting an instance of the other subtype using a differently named qualifier, but end up receiving the previously loaded type. This only happens after 3.1.5.
To Reproduce
Define two implementations of an abstract viewModel in a koin module. Example:
viewModel<AbstractViewModel>(named("First type")) { ConcreteViewModel1(get(), get(), get()) } viewModel<AbstractViewModel>(named("Second type")) { ConcreteViewModel2(get(), get(), get()) }
Pass an activity instance to platform agnostic class.
On that instance, call the extension function getViewModel(named("First type")). It should return the correct type (ConcreteViewModel1)
After that, try calling activity.getViewModel(named("Second type")). Notice the type returned is the wrong type, still ConcreteViewModel1
Koin project used and used version (please complete the following information):
koin-android 3.1.6 & koin-android 3.2.0
The text was updated successfully, but these errors were encountered: