https://kotlinlang.org logo
#koin-contributors
Title
# koin-contributors
v

Vivek Modi

01/22/2022, 4:50 PM
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

tynn

01/23/2022, 8:46 AM
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

Vivek Modi

01/25/2022, 2:24 PM
@tynn what do you mean by
Everything special to it won't have an effect
t

tynn

01/25/2022, 2:24 PM
Everything lifecycle related.
v

Vivek Modi

01/25/2022, 2:29 PM
@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

tynn

01/25/2022, 2:31 PM
I don’t really understand your question, sorry.
4 Views