# Vanilla Dagger - [x] Components must be abstract - [x] Favor Constructor injection over member injection - [x] Avoid unnecessary Provides methods and just constructor injection - [x] Favor Binds over Provides - [x] Methods annotated with `@Binds` must be abstract - [x] `@Provides` method should be static - [ ] If a Factory or Builder is present in a Component make sure it's called. - [x] If a class has `@Provides` or `@Binds` methods make sure it's annotated with `@Module`. - [x] valid provision methods - [x] val member injection methods - [x] `@Binds` return type is super type of impl - [ ] Suggest using KSP over KAPT # Anvil - [ ] Use `@MergeX` or `ContributesTo` annotations on Component and Subcomponents - [x] Use `@ContributesTo` annotations on each Module - [x] Favor `@ContributesBinding` over `@Binds` - [x] `@ContributesBinding` has a super class - [x] Cant be used in Java - [ ] Warn not compatible with KSP Dagger yet # Hilt - [x] Use `@InstallIn` annotations on each Module - [ ] Use `@InstallBinding` over `@Binds` (https://github.com/google/dagger/pull/3516) - [x] Don't forget hilt annotations (`@HiltAndroidApp`, `@AndroidEntryPoint`, `@HiltViewModel`) - [ ] use `by hiltViewModel()` for getting viewModels from DI Graph - [x] `@EntryPoint` can only be applied to interfaces - [x] Missing `@InstallIn` - [ ] Suggest using KSP over KAPT # Inspiration / Resources - [Keeping your Daggers sharp (Square)](https://medium.com/square-corner-blog/keeping-the-daggers-sharp-%EF%B8%8F-230b3191c3f) - [That Missing Guide: How to use Dagger2](https://zhuinden.medium.com/that-missing-guide-how-to-use-dagger2-ef116fbea97) - [Dagger 2 on Android: The Simple Way](https://proandroiddev.com/dagger-2-on-android-the-simple-way-f706a2c597e9) - [It's complicated, but it doesn't have to be: a Dagger journey ](https://youtu.be/9fn5s8_CYJI) - [Dagger 2 on Android: The Official Guidelines You Should Be Following](https://proandroiddev.com/dagger-2-on-android-the-official-guidelines-you-should-be-following-2607fd6c002e) - [Refactoring our Dependency Injection using Anvil](https://www.reddit.com/r/RedditEng/comments/10vla9g/refactoring_our_dependency_injection_using_anvil) - [Extending Anvil for Fun and Profit](https://slack.engineering/extending-anvil-for-fun-and-profit/) - [Dagger + Anvil: Learning to Love Dependency Injection on Android (Article)](https://gpeal.medium.com/dagger-anvil-learning-to-love-dependency-injection-on-android-8fad3d5530c9) - [Dagger + Anvil: Learning to Love Dependency Injection on Android (Droidcon talk)](https://www.droidcon.com/2022/06/28/dagger-anvil-learning-to-love-dependency-injection/) - [N26 Path to Anvil](https://marcellogalhardo.dev/posts/2021/02/05/n26-path-to-anvil/) - [Fragmented episode 202: Dagger on the Anvil with Ralf Wondratschek](https://fragmentedpodcast.com/episodes/202/) - [Dagger documentation](https://dagger.dev/) - [Anvil GitHub project](https://github.com/square/anvil)
Vanilla Dagger
@Bindsmust be abstract@Providesmethod should be static@Providesor@Bindsmethods make sure it's annotated with@Module.@Bindsreturn type is super type of implAnvil
@MergeXorContributesToannotations on Component and Subcomponents@ContributesToannotations on each Module@ContributesBindingover@Binds@ContributesBindinghas a super classHilt
@InstallInannotations on each Module@InstallBindingover@Binds(Add InstallBinding google/dagger#3516)@HiltAndroidApp,@AndroidEntryPoint,@HiltViewModel)by hiltViewModel()for getting viewModels from DI Graph@EntryPointcan only be applied to interfaces@InstallInInspiration / Resources