dependency-injection
Skill0 starsChanged 32 days agoMITView on GitHub
Hilt dependency-injection discipline for Android: constructor injection first, field injection only in entry points, @HiltViewModel with an @Inject constructor, module annotations, and no ViewModels passed to other classes. Use when writing or reviewing DI wiring (Hilt, Dagger, manual DI). Core rules have machine checks in checks/.
14 other projects use a version of this.
Adopted by
Most recently taken up by
- codewithmukesh/dotnet-claude-kittheir own version, first seen Nov 8, 2026
- AnyOrgName/php-skillstheir own version, first seen Nov 8, 2026
- jars-demo/jars-skillstheir own version, first seen Nov 1, 2026
- jame581/GodotPromptertheir own version, first seen Oct 21, 2026
- andr-ca/agentharnesstheir own version, first seen Oct 15, 2026
- Resgrid/Coretheir own version, first seen Oct 8, 2026
Used with
Projects with it also use api-versioning, caching and 7 more.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
wpankSkillapi-versioning
API versioning strategies — URL path, header, query param, content negotiation — with breaking change classification, deprecation timelines, migration patterns, and multi-version support. Use when evolving APIs, planning breaking changes, or managing version lifecycles.
Also in 3 projects that use this
wpankSkillcaching
Caching strategies, invalidation, eviction policies, HTTP caching, distributed caching, and anti-patterns. Use when designing cache layers, choosing eviction policies, debugging stale data, or optimizing read-heavy workloads.
Also in 3 projects that use this
diego-tobalinaSkilllogging
Logging best practices for Java (SLF4J/Logback) and Node.js (Winston/Pino). Use for structured logging, log levels, and avoiding sensitive data exposure.
Also in 4 projects that use this
ffsshhttiikkSkillopenapi
OpenAPI/Swagger specification and documentation
Also in 3 projects that use this
Model Context ProtocolSkillproject-structure
Where things live in the Inspector repo — which client owns which surface, what is in core/ versus clients/web, and what each top-level directory is for. Use when locating code, deciding where a new module belongs, or answering which package owns or contains a given area of the codebase.
Also in 3 projects that use this
harrissohail6Skillclean-architecture
Clean architecture and SOLID principles. Auto-activates when designing systems or refactoring code structure.
Also in 3 projects that use this
Other versions14 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 14
- trezor/trezor-suite★ 1.1ksame name
- jame581/GodotPrompter★ 870same name
- codewithmukesh/dotnet-claude-kit★ 808same name
- GoBetterAuth/go-better-auth★ 277same name
- Resgrid/Core★ 238same name
- garrettw/php-arch-skills★ 13same name
- AnyOrgName/php-skills★ 4same name
- HamzaSheikh768/Agents-Skills-Lap★ 3same name
- ffsshhttiikk/opencode-agents-skills★ 2same name
- kimtth/agent-skill-100-lines-or-less★ 2same name
4 more not listed
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository11 other files it gives its agents.
- android-testingSkill
- compose-architectureSkill
- compose-migrationSkill
- compose-multiplatformSkill
- compose-performanceSkill
- compose-testingSkill
- gradle-build-logicSkill
- kmp-fundamentalsSkill
- material3-themingSkill
- offline-firstSkill
- release-engineeringSkill
The file
We split this skill into the rules it gives an agent
7 rules. 0 are common, 4 are distinctive, and 3 are very specific to this project.
0
Common
Most of the 13 edited versions we read keep these.
4
Distinctive
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 15
After ANY DI wiring edit, run the Verification step (bottom of this file).
- Distinctive: line 19
MUST use constructor injection for regular classes — it keeps dependencies in the API surface and testable.
- Very specific: line 56
MUST annotate the ViewModel constructor with @Inject: "Provide a ViewModel by annotating it with @HiltViewModel and using the @Inject …
- Very specific: line 84
MUST put @Provides / @Binds methods inside a class annotated @Module — and every module MUST also carry @InstallIn(Component::class) to say …
- Distinctive: line 110
MUST NOT pass a ViewModel to other classes — including another ViewModel's constructor: "Don't pass ViewModels to other classes, functions …
- Distinctive: line 143
Run after every DI wiring edit (from the project root):
- Very specific: line 152
All four must pass (exit 0) before declaring the task done.
“Common” is measured: kept by at least 6 in 10 of the 13 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Dependency Injection
Operational rules for a coding agent. RIGHT/WRONG pairs are canonical. After ANY DI wiring edit, run the Verification step (bottom of this file).
1. Field injection only in entry points
MUST use constructor injection for regular classes — it keeps dependencies
in the API surface and testable. Field injection exists only because
system-instantiated Android classes (Application, Activity, Service,
BroadcastReceiver, ViewModel) cannot take constructor parameters: those
classes MUST be Hilt entry points — @AndroidEntryPoint (or
@HiltAndroidApp for the Application) — for their @Inject fields to be
populated. A @Inject lateinit var in a class that is not an entry point
stays null and crashes at runtime.
WRONG:
class LoginActivity : AppCompatActivity() {
@Inject
lateinit var loginRepository: LoginRepository // never populated
}RIGHT:
@AndroidEntryPoint
class LoginActivity : AppCompatActivity() {
@Inject
lateinit var loginRepository: LoginRepository
}
class UserRepository @Inject constructor(
private val api: UserApi,
)WHY: "Hilt can provide dependencies to other Android classes that have the @AndroidEntryPoint annotation" — without it there is no container to inject from. The DI guide prefers constructor injection for everything else: dependencies stay verifiable at compile time instead of hidden.
2. @HiltViewModel requires an @Inject constructor
MUST annotate the ViewModel constructor with @Inject: "Provide a
ViewModel by annotating it with @HiltViewModel and using the @Inject
annotation in the ViewModel object's constructor." The UI obtains it
through hiltViewModel() (Compose) or by viewModels() — never by
constructing it.
WRONG:
@HiltViewModel
class ProfileViewModel(
private val userRepository: UserRepository
) : ViewModel()RIGHT:
@HiltViewModel
class ProfileViewModel @Inject constructor(
private val userRepository: UserRepository
) : ViewModel()WHY: @HiltViewModel only registers the ViewModel with the ViewModelComponent; the @Inject constructor is what tells Hilt how to build it. Without it the project fails to compile.
3. Providers live inside modules
MUST put @Provides / @Binds methods inside a class annotated
@Module — and every module MUST also carry @InstallIn(Component::class)
to say where it is installed. @Binds goes in an abstract class module
(interface → implementation); @Provides goes in an object module
(third-party classes, builders).
WRONG:
class DataModule { // missing @Module
@Provides
fun provideAnalyticsService(): AnalyticsService = AnalyticsServiceImpl()
}RIGHT:
@Module
@InstallIn(SingletonComponent::class)
object DataModule {
@Provides
fun provideAnalyticsService(): AnalyticsService = AnalyticsServiceImpl()
}4. ViewModels are not dependencies
MUST NOT pass a ViewModel to other classes — including another ViewModel's constructor: "Don't pass ViewModels to other classes, functions or other UI components. Because the platform manages them, you should keep them as close to it as you can." A ViewModel that needs another screen's state should share a repository (or an activity-scoped ViewModel obtained by the owner), not receive a ViewModel via injection.
WRONG:
@HiltViewModel
class ProfileViewModel(
private val userViewModel: UserViewModel // ViewModel as a dependency
) : ViewModel()RIGHT:
@HiltViewModel
class ProfileViewModel @Inject constructor(
private val userRepository: UserRepository // share data, not ViewModels
) : ViewModel()5. What the checks cannot see (review-verified)
- Manual DI is legitimate for small apps (the guide documents it); the service-locator pattern is the discouraged middle ground — global state that makes tests interact with the same locator.
- Scoping choices (
@Singleton,@ViewModelScoped, custom components) and module organization across Gradle modules — verified by review.
Verification
Run after every DI wiring edit (from the project root):
bash <skill-dir>/checks/check_field_injection_entry_point.sh <kotlin-src-dir>
bash <skill-dir>/checks/check_hilt_viewmodel_inject.sh <kotlin-src-dir>
bash <skill-dir>/checks/check_provides_in_module.sh <kotlin-src-dir>
bash <skill-dir>/checks/check_no_viewmodel_in_viewmodel.sh <kotlin-src-dir>All four must pass (exit 0) before declaring the task done. Checks are deterministic heuristics — they catch the documented anti-patterns above, not every DI bug. §5 is verified by review against references/di.md.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

