HoangNguyen0403

Android Dependency Injection (Hilt)

Standards for Hilt Setup, Scoping, and Modules

HoangNguyen0403 501 148 Updated 4mo ago

Resources

1
GitHub

Install

npx skillscat add hoangnguyen0403/agent-skills-standard/android-dependency-injection-hilt

Install via the SkillsCat registry.

SKILL.md

Android Dependency Injection (Hilt)

Priority: P0

Implementation Guidelines

Setup

  • App: Must annotate Application class with @HiltAndroidApp.
  • Entries: Annotate Activities/Fragments with @AndroidEntryPoint.

Modules

  • Binding: Use @Binds (abstract class) over @Provides when possible (smaller generated code).
  • InstallIn: Be explicit (SingletonComponent, ViewModelComponent).

Construction

  • Constructor Injection: Prefer over Field Injection (@Inject constructor(...)).
  • Assisted Injection: Use for runtime parameters (@AssistedInject).

Anti-Patterns

  • Component Manual Creation: **No Manual Dagger**: Use Hilt Standard.
  • Field Inject in Logic: **No Field Inject**: Only in Android Components.

References

Categories