Hello everyone! How to inject viewModel with Dagger 2 (not Hilt) into composable?
Yes, i may inject VM into Activity and send as parameter into composable function. But i don't like this method because what to do if i have many VM's?
Earlier i inject VM's into fragments and this was fine.
j
julioromano
03/29/2021, 11:07 AM
AFAIK there is no built-in (i.e. provided by compose or androidx) support for injecting non-hilt dagger provided dependencies.
This means you have to create your own
ViewModel.Factory
(which will get dependencies from Dagger components) and then pass it when requesting a viewModel.
👍 1
s
Sanendak
03/29/2021, 11:09 AM
Thanks! I understood
l
Lucien Guimaraes
09/28/2021, 12:46 PM
Hey @Sanendak have you find a way to inject VM with pure dagger2 into composable ?