Koin DI, Repository Pattern & ViewModel in Kotlin Compose Desktop | Lesson 16
7views
1likes
026:35
T
Taught by Celeste AI - AI Coding Coach
View on YouTubeDescription
Learn dependency injection with Koin in Kotlin Compose Desktop! We build a Book Library app from scratch with clean architecture: repository
pattern, ViewModel with StateFlow, and Koin wiring it all together. Browse 18 books, search by title/author, favorite books, and view details
in a split-panel layout.
What You'll Learn:
- Setting up Koin 4.1.1 with koin-core and koin-compose dependencies
- Pinning Compose version with resolution strategy (avoiding Skiko native crash)
- Repository pattern: BookRepository interface + InMemoryBookRepository implementation
- ViewModel with constructor injection: LibraryViewModel takes BookRepository parameter
- StateFlow for reactive UI state management (LibraryUiState data class)
- Koin modules: dataModule (single) and uiModule (single with get())
- koinInject() in composables for automatic ViewModel injection
- KoinApplication wrapper in Main.kt for initialization
- Derived state with remember() for filtering and selection
- Testing with FakeBookRepository — 7 ViewModel tests with zero infrastructure
Timestamps:
0:00 - Introduction
0:15 - Preview: Architecture & Test Results
0:45 - Project Setup (Gradle with Koin Dependencies)
2:49 - Models & Repository (BookModels + BookRepository)
5:17 - ViewModel & DI (LibraryViewModel + AppModule)
7:26 - Book Item Composable
10:19 - Book Panels (BookDetail + BookList)
16:35 - App Content & Main + Compile
19:55 - Tests (LibraryViewModelTest + Run Tests)
23:46 - Live Demo: Book Library App
24:35 - Recap & Key Takeaways
25:35 - Thanks for Watching
Key Takeaways:
1. Koin Setup — koin-core + koin-compose, define modules with single { } and get()
2. Repository Pattern — Interface + implementation, swap in fakes for testing
3. ViewModel with DI — Constructor takes BookRepository, Koin resolves it automatically
4. Compose Integration — koinInject() replaces manual ViewModel creation
5. Testability — FakeBookRepository lets you test ViewModel logic with zero infrastructure
Previous Lesson:
Lesson 15: Testing — Weather App with JUnit4 & MockEngine
https://youtube.com/...
Next Lesson:
Lesson 17: Packaging & Distribution (coming soon)
Tech Stack:
Kotlin 2.1, Compose Multiplatform 1.7.3, Material3
Koin 4.1.1 (koin-core, koin-compose)
kotlinx-coroutines-test 1.9.0
Gradle 8.10, JVM 17+
Source Code: https://github.com/GoCelesteAI/kotlin_desktop_book_library
Taught by CelesteAI
If you found this helpful, please like and subscribe for more Kotlin Desktop tutorials!
#kotlin #compose #desktop #material3 #koin #dependencyinjection #repository #viewmodel #stateflow #tutorial #programming
Back to tutorialsOpen in YouTube
Duration
26:35
Published
February 23, 2026
Added to Codegiz
March 15, 2026