Skip to content

Instantly share code, notes, and snippets.

Created May 11, 2021 06:02
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save appspell/dc1b028ee621a5922657e01c5177c5ec to your computer and use it in GitHub Desktop.
inline fun <reified T : ViewModel> daggerViewModel(
key: String? = null,
crossinline viewModelInstanceCreator: () -> T
): T =
modelClass =,
key = key,
factory = object : ViewModelProvider.Factory {
override fun <T : ViewModel> create(modelClass: Class<T>): T {
return viewModelInstanceCreator() as T
Copy link

Thanks your code :)
Can I use your code in my commercial app?
Please let me know how I can use the code for commercial distribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment