android-di-koinlisted
Install: claude install-skill lenorebreakneck630/claude-zero-to-hero-android-KMP
# Android / KMP Dependency Injection (Koin)
## Principles
- One Koin module per feature layer — create it only if there are dependencies to provide.
- Modules are assembled in `:app`, never in feature modules themselves.
- In Compose root composables, always inject ViewModels via `koinViewModel()`.
---
## Module Definitions
Prefer the constructor-reference overloads (`singleOf`, `viewModelOf`, `factoryOf`) — they are more concise and let Koin resolve parameters automatically. Only fall back to the lambda overloads (`single { ... }`, `viewModel { ... }`, `factory { ... }`) when constructor injection alone is not enough, e.g. when you need to call a factory method, pass a named/qualified dependency, or do post-construction setup.
### Data layer module
```kotlin
// feature:notes:data
val notesDataModule = module {
singleOf(::RoomNoteRepository) { bind<NoteRepository>() }
}
```
### Presentation layer module
```kotlin
// feature:notes:presentation
val notesPresentationModule = module {
viewModelOf(::NoteListViewModel)
viewModelOf(::NoteDetailViewModel)
}
```
### Core data module (example)
```kotlin
// core:data
val coreDataModule = module {
// singleOf works when the class has a single injectable constructor
singleOf(::SessionPreferences)
// Lambda overload needed here — calling a factory method, not a constructor
single { HttpClientFactory.create(get()) }
single { createDataStore(get()) }
}
```
---
## Assembly in `:app`
Regist