Skip to content

Instantly share code, notes, and snippets.

@mlykotom
Last active January 3, 2020 09:46
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 mlykotom/76e7ed10b3543d9f082ca059a45972e6 to your computer and use it in GitHub Desktop.
Save mlykotom/76e7ed10b3543d9f082ca059a45972e6 to your computer and use it in GitHub Desktop.
Connecting The Dots :: Motivation - manually added dependencies
class SomeFragment : Fragment() {
// inject into this class omitted for brevity
@Inject
lateinit var dep1: Dependency
@Inject
lateinit var dep2: Dependency
lateinit var viewModel : SomeViewModel
override fun onCreate(savedState: Bundle?){
super.onCreate(savedState)
// retrieve articleId and pass it to your factory
val articleId = arguments!!.getString("article_id")
val factory = SomeViewModel.Factory(dep1, dep2, articleId)
viewModel = ViewModelProvider(this, factory).get(SomeViewModel::class.java)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment