From 2957227f69aeb293d7fd8d9b9d5cbaa2d8ca5a39 Mon Sep 17 00:00:00 2001 From: Antoine Jaury Date: Wed, 8 Jul 2026 16:37:06 +0200 Subject: [PATCH] refactor: improve PlaybackModule lifecycle management with `onClose` --- .../kotlin/bzh/ajaury/chombev/player/di/PlaybackModule.kt | 5 ++++- .../jvmTest/kotlin/bzh/ajaury/chombev/di/KoinModulesTest.kt | 3 +-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/data/playback/src/commonMain/kotlin/bzh/ajaury/chombev/player/di/PlaybackModule.kt b/data/playback/src/commonMain/kotlin/bzh/ajaury/chombev/player/di/PlaybackModule.kt index 7d1a69b..705c6b7 100644 --- a/data/playback/src/commonMain/kotlin/bzh/ajaury/chombev/player/di/PlaybackModule.kt +++ b/data/playback/src/commonMain/kotlin/bzh/ajaury/chombev/player/di/PlaybackModule.kt @@ -6,7 +6,10 @@ import org.koin.core.module.Module import org.koin.core.module.dsl.bind import org.koin.core.module.dsl.singleOf import org.koin.dsl.module +import org.koin.dsl.onClose val playbackModule: Module = module { - singleOf(::PlaybackRepositoryImpl) { bind() } + // Release the audio player when the app is destroyed: closing the composition-scoped Koin drops + // this single and fires onClose (only if it was ever created). + singleOf(::PlaybackRepositoryImpl) { bind() } onClose { it?.release() } } diff --git a/shared/src/jvmTest/kotlin/bzh/ajaury/chombev/di/KoinModulesTest.kt b/shared/src/jvmTest/kotlin/bzh/ajaury/chombev/di/KoinModulesTest.kt index 3a0cc09..818299e 100644 --- a/shared/src/jvmTest/kotlin/bzh/ajaury/chombev/di/KoinModulesTest.kt +++ b/shared/src/jvmTest/kotlin/bzh/ajaury/chombev/di/KoinModulesTest.kt @@ -1,7 +1,6 @@ package bzh.ajaury.chombev.di import bzh.ajaury.chombev.appModule -import bzh.ajaury.chombev.player.di.audioPlayerModule import bzh.ajaury.chombev.web.model.WebPage import org.koin.core.annotation.KoinExperimentalAPI import org.koin.test.verify.verify @@ -12,7 +11,7 @@ import kotlin.test.Test * the build if a dependency cannot be resolved from the declared modules. Acts as a compile-/build- * time safety net so DI misconfiguration surfaces in CI rather than at runtime. * - * Uses the JVM platform bindings (the `actual` [audioPlayerModule]); the shared graph is identical + * Uses the JVM platform bindings (the `actual` `audioPlayerModule`); the shared graph is identical * across targets, so verifying it here covers all of them. */ class KoinModulesTest {