https://kotlinlang.org logo
Title
m

Marcello Galhardo

10/29/2021, 7:01 PM
Hey all! I see Koin supports
FragmentFactory
but I don’t find a way to inject the Koin’s
ViewModelProvider.Factory
. The whole point of using
FragmentFactory
is to be able to do constructor injection. Is there any way to inject the
ViewModelProvider.Factory
in a
Fragment
constructor using Koin?
Otherwise, we could consider add an API for that. 🤔
a

arnaud.giuliani

11/02/2021, 11:12 AM
did you check
org.koin.androidx.fragment
sources, in
koin-android
?
there is the
KoinFragmentFactory
m

Marcello Galhardo

11/02/2021, 11:29 AM
Hm, I might not have expressed myself well. Let me rephrase: what I meant is that we need to inject the
ViewModelProvider.Factory
in the
Fragment
- that way I could pass a different VMP.Factory and test the
Fragment
in isolation without Koin. E.g.,
class MyFragment(
    private val factory: ViewModelProvider.Factory,
) : Fragment() {
    private val vm by viewModels { factory }
}
The
FragmentFactory
is working well with current set-up but I still need to use the Koin methods to access a VM, which creates a dependency between the Fragment and Koin. 🤔
:kotlin-intensifies: 1
a

arnaud.giuliani

11/02/2021, 11:50 AM
ok interesting 🤔 Not really taken into account for now 😕