Skip to content

Rule Ideas #1

Description

@WhosNickDoglio

Vanilla Dagger

  • Components must be abstract
  • Favor Constructor injection over member injection
  • Avoid unnecessary Provides methods and just constructor injection
  • Favor Binds over Provides
  • Methods annotated with @Binds must be abstract
  • @Provides method should be static
  • If a Factory or Builder is present in a Component make sure it's called.
  • If a class has @Provides or @Binds methods make sure it's annotated with @Module.
  • valid provision methods
  • val member injection methods
  • @Binds return type is super type of impl
  • Suggest using KSP over KAPT

Anvil

  • Use @MergeX or ContributesTo annotations on Component and Subcomponents
  • Use @ContributesTo annotations on each Module
  • Favor @ContributesBinding over @Binds
  • @ContributesBinding has a super class
  • Cant be used in Java
  • Warn not compatible with KSP Dagger yet

Hilt

  • Use @InstallIn annotations on each Module
  • Use @InstallBinding over @Binds (Add InstallBinding google/dagger#3516)
  • Don't forget hilt annotations (@HiltAndroidApp, @AndroidEntryPoint, @HiltViewModel)
  • use by hiltViewModel() for getting viewModels from DI Graph
  • @EntryPoint can only be applied to interfaces
  • Missing @InstallIn
  • Suggest using KSP over KAPT

Inspiration / Resources

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions