home / skills / hoangnguyen0403 / agent-skills-standard / di
This skill guides Android Hilt setup, modules, and constructor injection to enforce best practices and reduce boilerplate.
npx playbooks add skill hoangnguyen0403/agent-skills-standard --skill diReview the files below or copy the command above to add this skill to your agents.
---
name: Android Dependency Injection (Hilt)
description: Standards for Hilt Setup, Scoping, and Modules
metadata:
labels: [android, di, hilt, dagger]
triggers:
files: ['**/*Module.kt', '**/*Component.kt']
keywords: ['@HiltAndroidApp', '@Inject', '@Provides', '@Binds']
---
# 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
- [Module Templates](references/files.md)
This skill documents standards for setting up and using Hilt for dependency injection in Android projects. It focuses on correct annotations, module design, scoping choices, and anti-patterns to avoid. The goal is predictable, testable, and efficient DI wiring across Activities, Fragments, ViewModels, and application-level components.
The guidance enforces Hilt entry points by annotating the Application with @HiltAndroidApp and Android components with @AndroidEntryPoint. Modules should prefer @Binds for interface bindings and explicitly declare InstallIn scopes (e.g., SingletonComponent, ViewModelComponent). Constructor injection is the default; use Assisted Injection for runtime parameters.
Can I still use @Provides methods?
Yes — use @Provides when you need custom construction logic or cannot use @Binds, but prefer @Binds when binding interfaces to implementations.
When is field injection acceptable?
Only in Android framework classes (Activities, Fragments, Services) where constructor injection is not possible; keep business logic classes constructor-injected.