Hey folks, we are investigating Anvil as a DI solution. How do you make injection easer for Activities or Fragments?
m
mattinger
11/10/2021, 8:58 PM
I am investigating the same as well. Also looking at hilt. I don’t see any equivalent of @AndroidEntryPoint using anvil though.
mattinger
11/10/2021, 9:31 PM
My Thoughts:
• Anvil is less opinionated than Hilt
• Customizing the component per source tree is simpler in anvil
◦ the “replaces” feature in hilt is limited to the testing environment
◦ anvil allows replacement in the regular (non test) code
• Anvil lacks injection support
• The default components in Hilt don’t support @BindsInstance
• Testing in Hilt is very intrusive
◦ requires certain annotations
◦ requires a custom test runner
◦ pushing mocks into the graph is a little hokey
mattinger
11/10/2021, 9:34 PM
I haven’t made a decision yet, but the big thing hilt has going for it is the assisted injection. But i also need to try to build my .aar file and bring it into another hilt project and see if it properly combines the graphs (it should, but i’d like to verify)
h
Hakob Astvacatryan
11/10/2021, 10:07 PM
Hey thanks for sharing your investigation.
I’m searching for framework agnostic solution. Hilt is very tied to Android SDK and its functionality build around android’s core components such as Activity, Fragment, ViewModel. If you are not planning to use them long term hilt is not an option for you.