Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nimrodda/3d456b9c836740428047db214484099d to your computer and use it in GitHub Desktop.
Save Nimrodda/3d456b9c836740428047db214484099d to your computer and use it in GitHub Desktop.
class ViewModelFactory @Inject constructor(
private val creators: MutableMap<Class<out ViewModel>, Provider<ViewModel>>
) : ViewModelProvider.Factory {
override fun <T : ViewModel> create(modelClass: Class<T>): T {
return creators[modelClass]?.get() as? T
?: throw IllegalArgumentException("The requested ViewModel isn't bound")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment