← ClaudeAtlas

android-di-koinlisted

Koin dependency injection setup for Android/KMP - module definitions per layer, ViewModel injection, assembling modules in :app, and koinViewModel() in composables. Use this skill whenever setting up Koin, defining a DI module, providing a repository or ViewModel, injecting a dependency, or wiring modules in the Application class. Trigger on phrases like "set up Koin", "add a Koin module", "inject a dependency", "DI module", "koinViewModel", "provide a ViewModel", "startKoin", or "single/viewModel/factory".
lenorebreakneck630/claude-zero-to-hero-android-KMP · ★ 1 · AI & Automation · score 64
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