Agent skill
kotlin-di
Dependency Injection - Hilt, Koin, scopes, testing
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/testing/kotlin-di-pluginagentmarketpla-custom-plugin-kotlin-cdf5a297
SKILL.md
Kotlin DI Skill
Dependency Injection with Hilt and Koin.
Topics Covered
Hilt for Android
@HiltAndroidApp
class App : Application()
@Module
@InstallIn(SingletonComponent::class)
object AppModule {
@Provides @Singleton
fun provideDatabase(@ApplicationContext context: Context) =
Room.databaseBuilder(context, AppDatabase::class.java, "app.db").build()
@Provides
fun provideUserDao(db: AppDatabase) = db.userDao()
}
@HiltViewModel
class UserViewModel @Inject constructor(
private val repository: UserRepository
) : ViewModel()
Koin for Multiplatform
val appModule = module {
single { HttpClient(getEngine()) }
single { UserRepository(get()) }
viewModel { UserViewModel(get()) }
}
// Start Koin
startKoin {
modules(appModule)
}
// Inject
val repository: UserRepository by inject()
Testing with DI
@HiltAndroidTest
class UserViewModelTest {
@get:Rule val hiltRule = HiltAndroidRule(this)
@BindValue @JvmField
val repository: UserRepository = mockk()
@Inject lateinit var viewModel: UserViewModel
@Before fun setup() { hiltRule.inject() }
}
Troubleshooting
| Issue | Resolution |
|---|---|
| "No binding for..." | Add @Provides or @Binds |
| ViewModel not injected | Use hiltViewModel() in Compose |
Usage
Skill("kotlin-di")
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?