refactor: improve PlaybackModule lifecycle management with onClose

This commit is contained in:
2026-07-08 16:37:06 +02:00
parent 4f23e0eb54
commit 2957227f69
2 changed files with 5 additions and 3 deletions
@@ -6,7 +6,10 @@ import org.koin.core.module.Module
import org.koin.core.module.dsl.bind import org.koin.core.module.dsl.bind
import org.koin.core.module.dsl.singleOf import org.koin.core.module.dsl.singleOf
import org.koin.dsl.module import org.koin.dsl.module
import org.koin.dsl.onClose
val playbackModule: Module = module { val playbackModule: Module = module {
singleOf(::PlaybackRepositoryImpl) { bind<PlaybackRepository>() } // 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<PlaybackRepository>() } onClose { it?.release() }
} }
@@ -1,7 +1,6 @@
package bzh.ajaury.chombev.di package bzh.ajaury.chombev.di
import bzh.ajaury.chombev.appModule import bzh.ajaury.chombev.appModule
import bzh.ajaury.chombev.player.di.audioPlayerModule
import bzh.ajaury.chombev.web.model.WebPage import bzh.ajaury.chombev.web.model.WebPage
import org.koin.core.annotation.KoinExperimentalAPI import org.koin.core.annotation.KoinExperimentalAPI
import org.koin.test.verify.verify 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- * 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. * 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. * across targets, so verifying it here covers all of them.
*/ */
class KoinModulesTest { class KoinModulesTest {