What is d/w by `inject()` and `viewModel()`? I use...
# koin-contributors
v
What is d/w by
inject()
and
viewModel()
? I used both in when injecting in viewmodel and both works fine. I didn't figure out what the d/w in both. Which one need to use for viewModel. Any suggestions? Thanks
t
inject
will only resolve a (new) instance from Koin directly.
viewModel
will resolve the instance from the enclosed
ViewModelProvider
. So if you use
inject
, you don’t need to use the Android
ViewModel
at all. Everything special to it won’t have an effect.
v
@tynn what do you mean by
Everything special to it won't have an effect
t
Everything lifecycle related.
v
@tynn
Copy code
private val viewModel: ActivityViewModel by viewModels {
    SavedStateViewModelFactory(application, this)
}
what can I use in this
viewModel()
?
Because my application crash when I am using
inject()
Copy code
private val viewModel: ActivityViewModel by viewModel()
t
I don’t really understand your question, sorry.