https://kotlinlang.org logo
Join Slack
Powered by
# koin
  • r

    reactormonk

    05/22/2025, 10:12 AM
    404, how do I create a koin application in a @Preview? https://insert-koin.io/docs/reference/koin-compose/multiplatform#starting-a-koin-instance-from-compose
    ✅ 1
    a
    k
    • 3
    • 3
  • v

    Vaibhav Jaiswal

    05/23/2025, 3:45 PM
    I am facing this weird error My iOS app is crashing on Koin 4.0.4, even tho my dependencies are correctly declared in the module Chat Gpt says its a deadlock in koin Stack trace in thread
    ✅ 1
    p
    • 2
    • 7
  • s

    Sergio C.

    05/24/2025, 4:09 PM
    Hi, Isn't this dependency supposed to work on iOS? koin-compose-viewmodel-navigation In the documentation it says its compatible with Android/Multiplatform app, but it doesn't compile for iOS when using the NavHostController
    ✅ 1
    z
    p
    k
    • 4
    • 12
  • e

    Emilio Colindres

    05/25/2025, 11:12 PM
    Hi everyone. There's a something that i really, really want to work, but i can't figure out a way to get it right. Details in thread
    • 1
    • 4
  • l

    Leo N

    05/27/2025, 10:06 AM
    Hi friends, I am seeing this error on our server once in a while, when it is very busy:
    Copy code
    Scope 'org.koin.ktor.plugin.RequestScope@2016737454' is closed
    Has anyone else encountered this? Our library versions are:
    Copy code
    kotlinx-ktor = "2.3.13"
    koin = "3.5.3"
    kotlin = "1.9.10"
  • m

    mattinger

    05/27/2025, 5:22 PM
    So i was reading through the koin docs, because we're currently on anvil, and we're having to use the forked version to support kotlin 2.0. As such, we're evaluating other options, as we have no clear timeframe for when anvil itself will support the k2 compiler. One thing i'm not seeing that was able to do with anvil was to discover modules at runtime without an explicit reference to them, but it seems like you have to enumerate them all inside of your
    startKoin
    call. Just want to confirm i'm not missing anything
    ➕ 1
    w
    • 2
    • 14
  • c

    Cleveland Shaw

    05/28/2025, 11:08 AM
    Hi Koin team 👋 I’m currently working on a Kotlin Multiplatform (KMP) project using the following versions:
    Koin: 4.1.0-RC1
    Koin Annotations: 2.0.1-RC1
    Kotlin: 2.1.21
    Compose Multiplatform: 1.8.1
    KSP: 2.1.21-2.0.1
    Here are the dependencies involved:
    [libraries]
    koin-core = { module = "io.insert-koin:koin-core", version.ref = "koin" }
    koin-annotations = { module = "io.insert-koin:koin-annotations", version.ref = "koinAnnotations" }
    koin-ksp-compiler = { module = "io.insert-koin:koin-ksp-compiler", version.ref = "koinAnnotations" }
    koin-android = { module = "io.insert-koin:koin-android", version.ref = "koin" }
    koin-compose = { module = "io.insert-koin:koin-compose", version.ref = "koin" }
    koin-compose-viewmodel = { module = "io.insert-koin:koin-compose-viewmodel", version.ref = "koin" }
    This is my Gradle setup:
    implementation(libs.koin.core)
    implementation(libs.koin.compose)
    implementation(libs.koin.compose.viewmodel)
    api(libs.koin.annotations)
    I’m encountering an issue during build related to duplicate classes, and I believe it’s a conflict between koin-annotations and koin-core-annotations. Here’s the actual error message:
    A failure occurred while executing com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable
    > Duplicate class org.koin.core.annotation.InjectedParam found in modules koin-annotations-jvm-2.0.1-RC1.jar -> koin-annotations-jvm-2.0.1-RC1 (io.insert-koin:koin-annotations-jvm:2.0.1-RC1) and koin-core-annotations-jvm-4.1.0-RC1.jar -> koin-core-annotations-jvm-4.1.0-RC1 (io.insert-koin:koin-core-annotations-jvm:4.1.0-RC1)
    Duplicate class org.koin.core.annotation.Provided found in modules koin-annotations-jvm-2.0.1-RC1.jar -> koin-annotations-jvm-2.0.1-RC1 (io.insert-koin:koin-annotations-jvm:2.0.1-RC1) and koin-core-annotations-jvm-4.1.0-RC1.jar -> koin-core-annotations-jvm-4.1.0-RC1 (io.insert-koin:koin-core-annotations-jvm:4.1.0-RC1)
    It seems like there’s a conflict between koin-annotations and koin-core-annotations jars. Is there a recommended way to avoid this duplication? Should I be aligning versions differently or excluding one of the modules manually? Any guidance on how to cleanly resolve this in a KMP setup would be greatly appreciated 🙏 Thanks again for all your great work on Koin!
    👀 1
    a
    g
    • 3
    • 6
  • j

    Jonathan

    05/29/2025, 6:13 PM
    Does the Koin support scoping a
    ViewModel
    to a Dialog? I would like to extra scanning logic to a dialog and have it automatically cancel any pending jobs (
    flow
    collection) once the dialog is dismissed. Currently I'm remembering my viewmodel when my dialog is displayed and manually calling a "dismissed" function that cancels my pending job. It would be nice if there exist some facility in Koin that would allow me to scope my viewmodel to a Dialog and handle canceling the
    viewModelScope
    once it is removed.
  • c

    CRamsan

    05/30/2025, 2:56 AM
    Hello team, I am looking for some help regarding scopes and Composables. Here is a small demonstration of the problem I have. I have an application with multiple windows so I want to have component(in this example it is the
    ViewModelDependencies
    ) that I want to scope to be a
    singleton
    within a single Window of my application. I am not sure how to approach it, I have tried to use a
    rememberKoinModules(WindowModule)
    on each window but the singleton is shared across both windows. I also tried to use
    KoinScope<String>(UUID.random().toString()) {...}
    and put the
    rememberKoinModules(WindowModule)
    inside the scope but the
    ViewModelDependencies
    was still a singleton across both scopes. 🤔 I assume I am doing something wrong and I am not understanding something about the scoping API. Would someone have an idea for how to approach this problem?
    Copy code
    internal val WindowModule = module {
        single {
            ViewModelDependencies() 
        }
        viewModel {
            WindowViewModel()
        }
    }
    
    class WindowViewModel(
        private val dependencies: ViewModelDependencies,
    ) : ViewModel() {...}
    
    @Composable
    fun WindowScreen(
        viewModel: WindowViewModel= koinViewModel(),
    ) {...}
    
    fun main() = application {
        KoinApplication(
            application = {
                modules(...)
            }
        ) {
            Window(
                onCloseRequest = ::exitApplication,
                title = "Window 1",
            ) {
                WindowScreen()
            }
            Window(
                onCloseRequest = ::exitApplication,
                title = "Window 2",
            ) {
                WindowScreen()
            }
        }
    }
    • 1
    • 2
  • s

    Sergio C.

    05/30/2025, 10:04 AM
    Why is my state not being saved in SavedStateHandle when injecting with koin?
    Copy code
    val homeViewmodelModule = module {
        viewModel { (handle: SavedStateHandle) -> HomeViewmodel(handle, get()) }
    }
    
    class HomeViewmodel(
        handle: SavedStateHandle,
        private val datastore: DataStore<Preferences>,
    ) : ViewModel(), KoinComponent {
    
    private var _newState: String by handle.saved(
        key = "new_state",
        init = { "original" }
    )
    I set the state to _newState = "new state" send the app to the background, kill process and when restarting the value is the original
    e
    • 2
    • 13
  • m

    Meet

    06/04/2025, 5:15 AM
    koin IDE plugin forget password not work. i mean not any mail received for password reset. if any issue
    m
    • 2
    • 2
  • t

    Tal Zion

    06/04/2025, 8:26 AM
    Hello guys, I have a native KMP project and I am getting a crash on iOS This is the iOS Implementation
    Copy code
    class AppDelegate: NSObject, UIApplicationDelegate {
        func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
            
            doInitKoin(config: nil)
            FirebaseApp.configure()
            
            return true
        }
    }
    This is the common implementation
    Copy code
    Modules.kt
    
    expect val platformModule: Module
    
    val commonModule = module {
        singleOf(::RemoteFirebaseRepository).bind<FirebaseRepository>()
    }
    Copy code
    KoinHelper.kt
    
    // Common App Definitions
    fun appModule() = listOf(commonModule, platformModule)
    
    fun initKoin(config: KoinAppDeclaration? = null) {
        // Initialize Koin with the platform-specific module
        startKoin {
            config?.invoke(this)
            modules(appModule())
        }
    }
    Any help if highly appriciated
  • t

    Tim Winters

    06/05/2025, 1:23 PM
    I came across this issue: https://github.com/InsertKoinIO/koin-annotations/issues/103 and wanted to double check that I understood the current state of Koin Annotations. We have a multi-module android project (20 or so) that all use koin. We have interfaces defined in lower-level modules, with their implementations defined in higher level modules. Does the KSP compiler check not currently support this architecture?
  • o

    Olivier Patry

    06/07/2025, 10:41 AM
    It appears Koin 4.1.0 is released https://github.com/InsertKoinIO/koin/releases/tag/4.1.0, but I can't find corresponding artifacts. Am I misunderstanding or maybe there is a publication issue or the release in Github was made a bit in advance?
  • a

    arnaud.giuliani

    06/09/2025, 8:18 AM
    Sorry friday shipping is not a good idea 😅 Koin 4.1 has been republished. It should be available on maven central
    ✅ 1
    o
    • 2
    • 3
  • j

    John O'Reilly

    06/09/2025, 10:42 AM
    Was just quickly trying out new
    KoinApplicationPreview
    in 4.1.....should something like following work? I'm getting render issue as soon as I add the `koinViewModel`but I could be missing something else perhaps
    Copy code
    @Preview
    @Composable
    fun PreviewPlayerListView() {
        KoinApplicationPreview(application = { modules(appModule, commonModule(false)) }) {
            SomeComposable()
        }
    }
    
    @Composable
    fun SomeComposable() {
        val playerListViewModel = koinViewModel<PlayerListViewModel>()
        Text("hey there")
    }
    a
    m
    • 3
    • 30
  • j

    Jonathan

    06/09/2025, 4:18 PM
    I would like to have a ViewModel scoped to the BottomSheet. Using
    koinViewModel<VM_TYPE>()
    seems to scope it to the current NavHost route. What’s the recommended way to achieve this?
    a
    • 2
    • 4
  • a

    arnaud.giuliani

    06/10/2025, 1:15 PM
    Koin 4.1 is now released - here is the article https://blog.insert-koin.io/koin-4-1-safer-configurations-stronger-integrations-support-0d68a691b30f
    koinscroll 4
    🎉 5
    t
    o
    • 3
    • 5
  • r

    Roberto Fernandez Montero

    06/12/2025, 9:32 AM
    I'm not able to run a simple example with Koin (4.1) + KMP (Web & desktop target) + Koin Annotations (4.0,1RC) , having this error
    Copy code
    [ksp] --> Missing Definition for property 'settings : com.russhwolf.settings.Settings' in 'com.binshelve.data.local.UserRepository'. Fix your configuration: add definition annotation on the class.
    🧵 1
    ✅ 1
    k
    • 2
    • 13
  • a

    arnaud.giuliani

    06/13/2025, 4:56 PM
    I deployed Koin Annotations 2.0.1 & 2.1.0: https://github.com/InsertKoinIO/koin-annotations/releases/tag/2.0.1
    🚀 3
  • a

    arnaud.giuliani

    06/13/2025, 4:56 PM
    https://github.com/InsertKoinIO/koin-annotations/releases/tag/2.1.0
  • a

    arnaud.giuliani

    06/13/2025, 4:56 PM
    Version 2.1.0 is aligning on last Koin/Kotlin/KSP version
  • a

    arnaud.giuliani

    06/13/2025, 4:57 PM
    I also updated Koin Annotations Sharing Patterns for KMP: https://insert-koin.io/docs/reference/koin-annotations/kmp#sharing-patterns
    👍 1
  • j

    Jonathan

    06/13/2025, 8:47 PM
    I’m getting the following error when trying to use Koin annotations with a type annotated with
    @OptIn(ExperimentalPagingApi::class)
    This declaration needs opt-in. Its usage must be marked with ‘@androidx.paging.ExperimentalPagingApi’ or ‘@OptIn(androidx.paging.ExperimentalPagingApi::class)’
    Does Koin not support transitive Opt-in annotations? How are other people solving this issue?
    solved 1
    👍 1
    • 1
    • 1
  • d

    dazza5000

    06/16/2025, 7:34 PM
    Does anyone have suggestions on how to resolve / workaround this issue? https://github.com/InsertKoinIO/koin/issues/2221
    👀 1
    a
    • 2
    • 1
  • s

    simon.vergauwen

    06/25/2025, 8:46 AM
    Hey all 👋 Is there a better way to make
    onClose
    work on Desktop besides manually calling
    koin.close()
    from a ShutdownHook?
    Untitled.cpp
    a
    m
    • 3
    • 4
  • m

    Mario Andhika

    06/26/2025, 8:03 AM
    Any advantages of using the new Ktor integration, instead of the old-school way of using Koin with Ktor?
    s
    • 2
    • 1
  • f

    Farhazul Mullick

    06/26/2025, 10:47 AM
    Hey, Does koin instantly create allocations in heap, when we define definitions like single or its created when we call inject() in composable or inject() in a class?
    Copy code
    ex: startKoin{
        module{
           singe { ClassA(get()) }
        }
    
    }
    s
    • 2
    • 4
  • f

    Farhazul Mullick

    06/27/2025, 9:23 AM
    Hey, can anyone tell me, where to call this fn for best performance in MyApplication class or featureModules entrypoint?
    Copy code
    koin.waitAllStartJobs()
    s
    • 2
    • 11
  • t

    Tim Karagosian

    06/28/2025, 9:01 PM
    Hello all! I hope you’re doing great today! I am fairly new to Koin and DI and am trying to understand the testing side. Running individual tests and classes have no issues. But when running all my test classes via Gradle task I’m fighting against KoinAlreadyStarted at GlobalContext errors on all my Test classes that implement a ViewModel from Koin. Has anyone experienced this before and can advise? Maybe even testing best practices could be helpful. I’ve tried KoinRules and @Before/After for setup and cleanup too and I do not get a different error or result.
    k
    a
    • 3
    • 4