Reposting this question from March that didn't get...
# dagger
c
Reposting this question from March that didn't get any replies (except from Jake). Don't want to keep bothering one person. Can anyone chime in? I'm still learning dagger (did a big deep dive this past week) and I have a better grasp on it and components and subcomponents, etc, but I still don't understand the comments from people that say "If you use Dagger, you don't need AAC ViewModels". I would love to kill off AAC VM completely because I think the factory you need to create in order to pass in an argument is overkill and it seems like a properly scoped component would just be simpler in this case. (note: I also understand that this "hilt" thing is coming out soon, but I still would find this answer beneficial, even from a curiosity point of view. I'm trying to prevent someone from answering "Just wait till June 3rd")
a
This article by @Manuel Vivo sums it up. The idea is to basically have a @Component that survives config changes and then use Dagger’s scoping mechanism to persist objects between config changes. Since the Component survives, any injections for the same scope will return the same object.
👍 1
s
Wait a bit more dagger will support ACC VM out of box with new hilt module.
m
I don’t think you can completely remove AAC VM from your dependencies as it’s the only way to retain something across config changes in androidX (due to
onRetainCustomNonConfigurationInstance
being deprecated). As a workaround (and with a better API), you can use this wrapper (but it uses AAC VM under the hood even though is not part of the public API). https://stackoverflow.com/questions/57922225/onretaincustomnonconfigurationinstance-deprecated-in-androidx If you wait for Hilt, you will also have an
ActivityRetainedComponent
that you can use. But as Sinan said, you’ll also be able to inject AAC VMs with just a single annotation
@ViewModelInject
, so the burden of creating factories and using multibinding is taking away from you.
🎉 3
Thanks for that link Arunkumar! Glad to see it still helps despite how old it is lol
a
Thank you. It really is and explains the conclusion mainly
Surviving configuration changes is not an easy task, we all know that
Looking forward to Hilt, tried it sometime back, the graph is interesting. Nice to have out of the box support for config changes.
c
@Arun Thanks for that link! @Manuel Vivo Had no idea that the way to survive across config changes is being deprecated. Is it being deprecated for external use? (i.e. doesn't AAC VM still need to use it in order to survive?) "creating factories and using multibinding" Oh boy. That went over my head. Not familiar enough with dagger to know when I would do that. But either way... it sounds like hilt will really be beneficial for us. I haven't used dagger-android, even though I know it's going away, but I would have thought that it would have just done that for us? Anyway. Excited for hilt! I will say that I'm still curious about why people on reddit (I believe Jake included [I know jake has strong opinions about a lot of these things]), but I'm just curious why people on reddit will sometimes go "You don't need AAC VM if you already use dagger"