-
-
Notifications
You must be signed in to change notification settings - Fork 714
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiple instances of android ViewModel #539
Comments
My theory is that this is expected behavior, because for
Notice parameters:
This way koin is provided But your use case seems weird to me, If I want to communicate between two viewModels I do so through some repository or some kind of shared data holder that has scope "longer" than given viewModels - I avoid communicating direcly between them |
as explained by @Ejstn i think maybe you can try:
|
Maybe you could use the |
ViewModel are more intended to be tied to the Activity/Fragment lifecycle stuff ... else extract component from them. Don't try to inject VM between them, not sure this is a good use case 🤔 |
I've noticed a bug that is very similar to the #145
If ViewModel is created as a constructor parameter of another ViewModel then it can be created multiple times.
To Reproduce
FirstViewModel
andSecondViewModel
) whereSecondViewModel
hasFirstViewModel
as a constructor parameter.Example:
SomeClass
has different instance ofFirstViewModel
thanSecondViewModel
Expected behavior
Only one instance of FirstViewModel should be created.
Koin project used and used version (please complete the following information):
koin-core version 2.0.1
koin-androidx-viewmodel version 2.0.1
The text was updated successfully, but these errors were encountered: