From 17da9f675727414691fe8e7f547665b49faea731 Mon Sep 17 00:00:00 2001 From: Antoine Jaury Date: Tue, 9 Jun 2026 17:22:43 +0200 Subject: [PATCH] refactor: integrate Koin for dependency injection across platforms --- README.md | 7 ++++++- androidApp/build.gradle.kts | 2 +- androidApp/src/main/AndroidManifest.xml | 1 + .../kotlin/fr/ajaury/gwenedeg/GwenedegApp.kt | 5 +++++ desktopApp/build.gradle.kts | 2 +- .../main/kotlin/fr/ajaury/gwenedeg/main.kt | 3 ++- gradle/libs.versions.toml | 7 +++++++ shared/build.gradle.kts | 7 +++++++ .../kotlin/fr/ajaury/gwenedeg/App.kt | 20 ++++++++++--------- .../kotlin/fr/ajaury/gwenedeg/di/Modules.kt | 14 +++++++++++++ .../gwenedeg/records/ui/RecordsScreen.kt | 12 ++++++++++- .../fr/ajaury/gwenedeg/MainViewController.kt | 1 + webApp/build.gradle.kts | 3 ++- .../webMain/kotlin/fr/ajaury/gwenedeg/main.kt | 2 ++ 14 files changed, 71 insertions(+), 15 deletions(-) create mode 100644 androidApp/src/main/kotlin/fr/ajaury/gwenedeg/GwenedegApp.kt create mode 100644 shared/src/commonMain/kotlin/fr/ajaury/gwenedeg/di/Modules.kt diff --git a/README.md b/README.md index dcbe6cd..7c966b7 100644 --- a/README.md +++ b/README.md @@ -43,4 +43,9 @@ Learn more about [Kotlin Multiplatform](https://www.jetbrains.com/help/kotlin-mu [Kotlin/Wasm](https://kotl.in/wasm/)… We would appreciate your feedback on Compose/Web and Kotlin/Wasm in the public Slack channel [#compose-web](https://slack-chats.kotlinlang.org/c/compose-web). -If you face any issues, please report them on [YouTrack](https://youtrack.jetbrains.com/newIssue?project=CMP). \ No newline at end of file +If you face any issues, please report them on [YouTrack](https://youtrack.jetbrains.com/newIssue?project=CMP). + +## Dependency injection + +For dependency injection, we use [Koin](https://insert-koin.io/). To know more about the integration with Compose, +please refer to the [Koin Compose documentation](https://insert-koin.io/docs/reference/koin-compose/compose). \ No newline at end of file diff --git a/androidApp/build.gradle.kts b/androidApp/build.gradle.kts index 2a70c44..bb56f11 100644 --- a/androidApp/build.gradle.kts +++ b/androidApp/build.gradle.kts @@ -14,8 +14,8 @@ kotlin { dependencies { implementation(projects.shared) + // Compose implementation(libs.androidx.activity.compose) - implementation(libs.compose.uiToolingPreview) debugImplementation(libs.compose.uiTooling) } diff --git a/androidApp/src/main/AndroidManifest.xml b/androidApp/src/main/AndroidManifest.xml index 26403a7..3499af4 100644 --- a/androidApp/src/main/AndroidManifest.xml +++ b/androidApp/src/main/AndroidManifest.xml @@ -2,6 +2,7 @@ () } + viewModelOf(::RecordsViewModel) +} diff --git a/shared/src/commonMain/kotlin/fr/ajaury/gwenedeg/records/ui/RecordsScreen.kt b/shared/src/commonMain/kotlin/fr/ajaury/gwenedeg/records/ui/RecordsScreen.kt index 5627272..5ed0a8e 100644 --- a/shared/src/commonMain/kotlin/fr/ajaury/gwenedeg/records/ui/RecordsScreen.kt +++ b/shared/src/commonMain/kotlin/fr/ajaury/gwenedeg/records/ui/RecordsScreen.kt @@ -14,11 +14,21 @@ import androidx.compose.runtime.getValue import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp import androidx.lifecycle.compose.collectAsStateWithLifecycle +import fr.ajaury.gwenedeg.records.domain.Record import fr.ajaury.gwenedeg.records.ui.viewmodel.RecordsViewModel +import org.koin.compose.viewmodel.koinViewModel @Composable -fun RecordsScreen(viewModel: RecordsViewModel) { +fun RecordsScreen(viewModel: RecordsViewModel = koinViewModel()) { val records by viewModel.uiState.collectAsStateWithLifecycle() + + RecordsScreen( + records = records, + ) +} + +@Composable +fun RecordsScreen(records: List) { Scaffold { innerPadding -> LazyColumn( modifier = diff --git a/shared/src/iosMain/kotlin/fr/ajaury/gwenedeg/MainViewController.kt b/shared/src/iosMain/kotlin/fr/ajaury/gwenedeg/MainViewController.kt index 454b9b8..a4d92bf 100644 --- a/shared/src/iosMain/kotlin/fr/ajaury/gwenedeg/MainViewController.kt +++ b/shared/src/iosMain/kotlin/fr/ajaury/gwenedeg/MainViewController.kt @@ -2,4 +2,5 @@ package fr.ajaury.gwenedeg import androidx.compose.ui.window.ComposeUIViewController +@Suppress("ktlint:standard:function-naming") fun MainViewController() = ComposeUIViewController { App() } diff --git a/webApp/build.gradle.kts b/webApp/build.gradle.kts index 865afe9..cca7888 100644 --- a/webApp/build.gradle.kts +++ b/webApp/build.gradle.kts @@ -22,7 +22,8 @@ kotlin { commonMain.dependencies { implementation(projects.shared) + // Compose implementation(libs.compose.ui) } } -} \ No newline at end of file +} diff --git a/webApp/src/webMain/kotlin/fr/ajaury/gwenedeg/main.kt b/webApp/src/webMain/kotlin/fr/ajaury/gwenedeg/main.kt index 8f1ef28..c4d81e4 100644 --- a/webApp/src/webMain/kotlin/fr/ajaury/gwenedeg/main.kt +++ b/webApp/src/webMain/kotlin/fr/ajaury/gwenedeg/main.kt @@ -1,3 +1,5 @@ +@file:Suppress("ktlint:standard:filename") + package fr.ajaury.gwenedeg import androidx.compose.ui.ExperimentalComposeUiApi