Hello everyone! How to inject viewModel with Dagge...
# compose
s
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
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
Thanks! I understood
l
Hey @Sanendak have you find a way to inject VM with pure dagger2 into composable ?
s
@Lucien Guimaraes hi! Try this. Personally I switched to Hilt :) https://proandroiddev.com/dagger-2-and-jetpack-compose-integration-8a8d424ffdb4
l
Thanks!
785 Views