Thread
#android-architecture
    Rafal

    Rafal

    1 year ago
    Is it ok to inject a
    ViewModel
    into another
    ViewModel
    ? I have one
    ViewModel
    scoped to an Activity and the second one scoped to a Fragment that could use one
    flow
    from the Activity one
    Javier

    Javier

    1 year ago
    I think you are looking for a shared ViewModel instead of injecting one VM in another one
    Rafal

    Rafal

    1 year ago
    oh, thanks! I’ll check that out 📖
    Will Shelor

    Will Shelor

    1 year ago
    If that doesn’t work, my personal thought (not knowing that much about your situation or scope) would probably be to have the fragment subscribe to the flow, and call its viewmodel when the root VM updated- if they truly are distinct conceptually.
    Ariel Bogdziewicz

    Ariel Bogdziewicz

    1 year ago
    Common code for view model is use case
    marlonlom

    marlonlom

    1 year ago
    Mmm @Rafal i think you could use the repository/use cases that are common to use inside the viewmodel, the purpose of the viewmodel is to have one per screen 😃