Skip to content

Commit 2e11790

Browse files
committed
Import and setup Koin for multiplatform dependency injection
Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
1 parent 4fda42f commit 2e11790

4 files changed

Lines changed: 62 additions & 3 deletions

File tree

composeApp/build.gradle.kts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,23 @@ kotlin {
4444
implementation(compose.ui)
4545
implementation(compose.components.resources)
4646
implementation(compose.components.uiToolingPreview)
47+
48+
// Lifecycle
4749
implementation(libs.jetbrains.lifecycle.viewmodel)
50+
51+
// Koin
52+
implementation(project.dependencies.platform(libs.koin.bom))
53+
api(libs.koin.annotations)
54+
implementation(libs.koin.core)
55+
implementation(libs.koin.compose)
56+
implementation(libs.koin.viewmodel)
4857
}
4958
commonTest.dependencies {
5059
implementation(libs.kotlin.test)
60+
61+
// Koin
62+
implementation(project.dependencies.platform(libs.koin.bom))
63+
implementation(libs.koin.test)
5164
}
5265
androidMain.dependencies {
5366
implementation(compose.preview)
@@ -58,8 +71,24 @@ kotlin {
5871
implementation(libs.jetbrains.kotlinx.coroutinesSwing)
5972
}
6073
}
74+
75+
// Koin
76+
sourceSets.named("commonMain").configure {
77+
kotlin.srcDir("build/generated/ksp/metadata/commonMain/kotlin")
78+
}
79+
}
80+
81+
// Koin
82+
dependencies {
83+
add("kspCommonMainMetadata", libs.koin.annotations)
84+
add("kspAndroid", libs.koin.compiler)
85+
add("kspIosArm64", libs.koin.compiler)
86+
add("kspIosSimulatorArm64", libs.koin.compiler)
6187
}
6288

89+
tasks.matching { it.name.startsWith("ksp") && it.name != "kspCommonMainKotlinMetadata" }
90+
.configureEach { dependsOn("kspCommonMainKotlinMetadata") }
91+
6392
compose.desktop {
6493
application {
6594
mainClass = "net.newpipe.app.MainKt"

composeApp/src/commonMain/kotlin/net/newpipe/app/App.kt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,22 @@
66
package net.newpipe.app
77

88
import androidx.compose.runtime.Composable
9+
import net.newpipe.app.module.appModules
910
import net.newpipe.app.theme.AppTheme
10-
import org.jetbrains.compose.ui.tooling.preview.Preview
11+
import org.koin.compose.KoinMultiplatformApplication
12+
import org.koin.core.annotation.KoinExperimentalAPI
13+
import org.koin.dsl.koinConfiguration
1114

15+
@OptIn(KoinExperimentalAPI::class)
1216
@Composable
13-
@Preview
1417
fun App() {
15-
AppTheme {
18+
KoinMultiplatformApplication(
19+
config = koinConfiguration {
20+
modules(appModules)
21+
}
22+
) {
23+
AppTheme {
1624

25+
}
1726
}
1827
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2026 NewPipe e.V. <https://newpipe-ev.de>
3+
* SPDX-License-Identifier: GPL-3.0-or-later
4+
*/
5+
6+
package net.newpipe.app.module
7+
8+
import org.koin.dsl.module
9+
10+
val appModules = module {
11+
12+
}

gradle/libs.versions.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ hotreload = "1.0.0"
2626
jsoup = "1.21.2"
2727
junit = "4.13.2"
2828
junit-ext = "1.3.0"
29+
koin-annotations = "2.3.1"
30+
koin-bom = "4.1.1"
2931
kotlin = "2.2.21"
3032
ksp = "2.3.2"
3133
ktlint = "1.8.0"
@@ -117,6 +119,13 @@ jetbrains-kotlinx-coroutinesSwing = { module = "org.jetbrains.kotlinx:kotlinx-co
117119
jetbrains-lifecycle-viewmodel = { module = "org.jetbrains.androidx.lifecycle:lifecycle-viewmodel-compose", version.ref = "lifecycle-jetbrains" }
118120
jsoup = { module = "org.jsoup:jsoup", version.ref = "jsoup" }
119121
junit = { module = "junit:junit", version.ref = "junit" }
122+
koin-annotations = { module = "io.insert-koin:koin-annotations", version.ref = "koin-annotations" }
123+
koin-bom = { module = "io.insert-koin:koin-bom", version.ref = "koin-bom" }
124+
koin-compiler = { module = "io.insert-koin:koin-ksp-compiler", version.ref = "koin-annotations" }
125+
koin-compose = { module = "io.insert-koin:koin-compose" }
126+
koin-core = { module = "io.insert-koin:koin-core" }
127+
koin-test = { module = "io.insert-koin:koin-test" }
128+
koin-viewmodel = { module = "io.insert-koin:koin-compose-viewmodel" }
120129
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" }
121130
lisawray-groupie-core = { module = "com.github.lisawray.groupie:groupie", version.ref = "groupie" }
122131
lisawray-groupie-viewbinding = { module = "com.github.lisawray.groupie:groupie-viewbinding", version.ref = "groupie" }

0 commit comments

Comments
 (0)