Skip to content

ViewModel constructor injection #440

@volo-droid

Description

@volo-droid

This library seems to be long time abandoned, but if one day you like I find yourself on a project that uses Toothpick and question how to perform a constructor injection of ViewModel without too much hassle have a look at the following Gist:

https://gist.github.com/volo-droid/54d4443c28ec92ecb0a0741d16d4c47c

It allows to inject ViewModel in a simpler way.

class MainFragment : Fragment() {
    
    private val viewModel by viewModelOf(::MyViewModel)
    
    private val sharedViewModel by activityViewModelOf(::MySharedViewModel)
    
    //
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions