Hi Everyone, I'm facing a bug related to the `koin...
# koin-contributors
h
Hi Everyone, I'm facing a bug related to the
koin
implementation of the
FragmentFactory
. Basically, if you inject a
ViewModel
in the constructor of the
Fragment
, this one will be instantiated again if you rotate the screen. This bug is reproducible only injecting the
ViewModel
via the fragment constructor but is not possible to reproduce it injecting the
ViewModel
via the lazy extension
viewModel()
Let me know if you are already aware of this bug or I can open an issue on Github.
t
If you use
get()
to obtain your view model within your fragment factory, it’s the expected behavior.
If you don’t use the fragment itself as the
ViewModelStoreOwner
to obtain the view model, you could use
ViewModelStoreOwner.getViewModel<Model>()
instead.
a
I agree here, we need a ViewModelStoreOwner to inject a ViewModel instance the right way
h
Sorry I just noticed the comments. So I have to create a
ViewModelStoreOwner
in some way and then use it to inject the
ViewModel
?
a
A Fragment is a
ViewModelStoreOwner
the thing is trying to inject it by constructor
don’t know how the ViewModelFactory can be triggered from the constructor, need to check a bit