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

    Dallasphillips24

    08/24/2025, 3:21 PM
    This is the stacktrace provided by logcat.
    2025-08-24 080018.155 6214-6214 A.txt
  • d

    Dallasphillips24

    08/24/2025, 3:22 PM
    This has been blocking me for over a week and so far have not gotten any help from github or here. Hopefully the image gives more context this time along with the stacktrace.
  • w

    WukongRework.exe

    08/26/2025, 11:48 PM
    Hello everyone, currently running into a weird issue with Koin in a Compose multiplatform project. I have my DI set up with Koin using
    KoinMultiplatformApplication
    and I’m running into a
    ClosedScopeException
    when rotating the screen. A bit of googling later leads me to this GitHub issue https://github.com/InsertKoinIO/koin/issues/1773 but the suggested solution of using
    KoinContext
    doesn’t appear to be a valid solution anymore as the function has been deprecated in 4.1.0 (which I am using). Does anyone know if there is a new API to use in 4.1.0 to fix this issue? Thanks in advance!
    ✅ 1
    a
    • 2
    • 5
  • u

    Umit AYDIN

    08/27/2025, 10:38 PM
    Wondering if I can use in memory Room database with populated initial data extending RoomDatabase.Callback for Compose Previews. Any ideas 🤔?
  • m

    Marc

    08/28/2025, 10:14 AM
    Hey guys maybe a silly question: Is there some way to intercept the Koin plugin so we can add modules ad hoc? let me explain: on a Ktor project I’m trying to set up I would like to modularize the features so each feature provides their own DI modules (that latter on they will be provided on the koin plugin. What I’m trying to do? instead of defining the di module in the feature and then provide i in the main application plugin, something like this:
    Copy code
    // In my feature module
    val featureModule = module {
        singleOf(::WhateverImplementation){ binds<WateverInterface>() }
    
    // Main app module
    ...
    install(Koin) {
       modules(featureModule)
    }
    I’d like something like (pseudocode)
    Copy code
    //feature module
    fun Application.featurePlugin() {
    -> inject here the featureModule to Koin
    
    rest of the feature configuration
    }
    
    // main app module
    fun Application.main() {
        featurePlugin() <- this way I can keep all configs isolated into feature module and i just need to add it into a single entry point
    }
    Does it make sense? is there any solution/idea already implemented or that would make more sense than this? ty!
    a
    • 2
    • 3
  • e

    esdrasdl

    08/28/2025, 7:52 PM
    Hello, I'm facing the following crash in my iOS app. It happens when the koin dependency tree is loaded. It's happening in a few versions of iOS (17.5.1, 18.3.2, 16.6.1). At the most recent version of iOS the crash not happens... My Koin version is 4.0.4 From : crashlytics
    Copy code
    Crashed: com.apple.main-thread
    0x14f28 class_rw_t::methods() const
    0x125a8 class_copyMethodList
    0x21ae42c createTypeInfo(objc_class*, TypeInfo const*, TypeInfo const*)
    0x21ae274 getOrCreateTypeInfo(objc_class*)
    0x1de4850 kfun:kotlinx.cinterop.internal.ObjectiveCKClassImpl#hashCode(){}<http://kotlin.Int|kotlin.Int> + 1852 (Primitives.kt:1852)
    0x1e2bd7c kfun:kotlin.collections.HashMap.findKey#internal + 40 (Any.kt:40)
    0x1e28e2c kfun:kotlin.collections.HashMap#get(1:0){}1:1? + 111 (HashMap.kt:111)
    0x1f151b0 kfun:co.touchlab.stately.collections.ConcurrentMutableMap.ConcurrentMutableMap$get$1.invoke#internal + 27 (ConcurrentMutableMap.kt:27)
    0x1f0f690 kfun:co.touchlab.stately.concurrency.Synchronizable#runSynchronized(kotlin.Function0<0:0>){0§<kotlin.Any?>}0:0 + 1 ([K][Suspend]Functions:1)
    0x1f13d68 kfun:co.touchlab.stately.collections.ConcurrentMutableMap#get(1:0){}1:1? + 27 (ConcurrentMutableMap.kt:27)
    0x1f243cc kfun:org.koin.ext#getFullName__at__kotlin.reflect.KClass<*>(){}kotlin.String + 85 (Map.kt:85)
    0x1f1c94c kfun:org.koin.core.module.Module#indexPrimaryType(org.koin.core.instance.InstanceFactory<*>){} + 100 (BeanDefinition.kt:100)
    0x217a5a0 kfun:my.package.core.network.networkModule$1.$<bridge-DNN>invoke(org.koin.core.module.Module){}#internal + 112 (Module.kt:112)
    0x1f2408c kfun:org.koin.dsl#module(kotlin.Boolean;kotlin.Function1<org.koin.core.module.Module,kotlin.Unit>){}org.koin.core.module.Module + 38 (ModuleDSL.kt:38)
    0x21843fc kfun:my.package.startComposeModules$1.$<bridge-DNN>invoke(org.koin.core.KoinApplication){}#internal + 33 (ModuleDSL.kt:33)
    0x1f27ba8 kfun:org.koin.core.context.MutableGlobalContext#startKoin(kotlin.Function1<org.koin.core.KoinApplication,kotlin.Unit>){}org.koin.core.KoinApplication + 1 ([K][Suspend]Functions:1)
    0x219c764 objc2kotlin_kfun:my.package#startComposeModules(kotlin.String;kotlin.Function0<platform.Foundation.NSURLCredential?>){} + 41 (DefaultContextExt.kt:41)
    0xae2b8 specialized AppDelegate.application(_:didFinishLaunchingWithOptions:) + 25 (AppDelegate.swift:25)
    0xacfe8 @objc AppDelegate.application(_:didFinishLaunchingWithOptions:) (<compiler-generated>)
    Do you have any clues? My coworker tried to increase the koin version to 4.1.0 but the crash still happens but with a different stracktrace
    Copy code
    Can't show file for stack frame : <DBGLLDBStackFrame: 0x367d4abb0> - stackNumber:4 - name:kfun:kotlinx.cinterop.internal.ObjectiveCKClassImpl#hashCode(){}<http://kotlin.Int|kotlin.Int> [inlined] kfun:kotlinx.cinterop.internal.ObjectiveCKClassImpl#<get-typeInfo>(){}kotlin.native.internal.NativePtr [inlined]. 
    The file path does not exist on the file system: /opt/buildAgent/work/2d153abd4d2c0600/kotlin/kotlin-native/Interop/Runtime/src/native/kotlin/kotlinx/cinterop/internal/ObjectiveCKClassImpl.kt
    ✅ 1
    a
    • 2
    • 4
  • d

    Dallasphillips24

    08/29/2025, 3:14 AM
    Is Koin even being maintained anymore? There is virtually no activity with GitHub or really this channel.
    f
    • 2
    • 5
  • g

    galex

    08/29/2025, 6:48 AM
    Hello, is Koin-annotations compatible with the new nav3 that is now (or should be really soon) usable in CMP/KMP ? Especially with everything related to ViewModels? Related -> https://github.com/android/nav3-recipes/issues/29#issuecomment-2975428493
    👀 1
    a
    • 2
    • 1
  • r

    Roger Kreienbühl

    08/31/2025, 10:30 AM
    Hi everyone I am using koin wuth koin-annotations. Now I am Adding a logger and want to have a factory, that I can pass a tag, that creates a new logger with that tag. This I achieve with the following code:
    Copy code
    @Factory
    fun provideLogger(@InjectedParam tag: String?): Logger {
        return if (tag != null) logger.withTag(tag) else logger
    }
    Now I am wondering, how I can pass the tag when creating for example a singleton:
    Copy code
    @Single
    class SomeService(logger: Logger) { ... }
    Is there any solution to this?
    f
    • 2
    • 5
  • r

    Renz

    09/02/2025, 12:52 AM
    Hi I successfully used koin in my project now I am refactoring. When I create a base class for my view model koin cant seem to create an instance of the concrete view model why is that ? This code works if i remove the base view model
    Copy code
    abstract class BaseViewModel<V : BaseViewModelState<U>, U : BaseUiState> : ViewModel()
    Copy code
    class MainViewModel(
        private val cardSetUseCase: CardSetUseCase
    ) : BaseViewModel<MainViewModelState, MainUiState>()
    Copy code
    val viewModelModule = module {
        viewModelOf(::MainViewModel)
    }
    ✅ 1
    a
    • 2
    • 2
  • d

    Dallasphillips24

    09/03/2025, 12:12 AM
    I am guessing you can't really (or are not supposed to) mix annotations and DSL? I want to add a module after application start so the NavController can be shared/used by ViewModels but the build time configuration gives complaints and disabling it causes runtime issues.
    a
    a
    • 3
    • 5
  • j

    Jonathan

    09/05/2025, 2:53 PM
    When using Koin in a KMP project, do you need to add koin-android dependency in the Android source set in addition to the koin-core dep. in the common source set?
    ✅ 1
    v
    • 2
    • 1
  • j

    Jonathan

    09/07/2025, 2:19 AM
    Is it possible to use context isolation w/ a KMP library using annotations? The problem I'm running into is how to properly initialize the KoinApplication with platform specific arguments such as Context for Android.. The Context Isolation example here has the application as a property on the "isolated context" so it's not possible to pass in the arguments. I could possible make the koinApp property a
    lateinit
    and enforce calling an "init" function at startup but that seems messy. Is there an obvious solution that I'm missing?
    a
    • 2
    • 4
  • o

    Ori Spokoini

    09/08/2025, 8:18 AM
    Hi everyone 👋 when using Koin annotations, is it possible to inject objects across different modules? For example core/ui/.../ProfileEditorViewModel.kt
    @KoinViewModel
    class ProfileEditorViewModel(
    private val userRepository: UserRepository
    ) : ViewModel()
    And in composeApp/.../FakeUserRepo.kt
    @Factory
    class FakeUserRepo() : UserRepository
    Currently I’m using
    @Provided
    to suppress the injection error and then manually loading
    FakeUserRepo
    . I also tried
    ComponentScan
    , but it doesn’t seem to work across modules. What’s the recommended way to handle this?
    a
    • 2
    • 4
  • s

    s3rius

    09/09/2025, 12:24 PM
    Hey everyone. I was wondering how you guys organize various tiny dependencies that are sometimes needed for a class, in Koin Annotations. For example, let's say there's an
    ApiClient
    class that needs a bunch of inputs. Basically like this:
    Copy code
    @Single
    class ApiClient(
        val baseUrl: String,
        val enableLogging: Boolean,
        val cacheDirectory: Path,
        val authClientId: String,
        ...
    )
    There are a few ways of providing these dependencies: 1. Tagging them all as ``@InjectedParam`` and doing a ``getApiClient { parametersOf(...) }`` once at the start of the app (to create the singleton). But this seems pretty shaky: it fails to work well with several parameters of the same type (such as ``baseUrl`` and ``authClientId``) and there's no compile-time safety. 2. Adding all those dependencies to Koins dependency graph via ``@Single`` or ``single()``, etc, using ``named<>`` to differentiate them. But that seems like you're polluting the dependency graph with dependencies that are really just details of a particular use-case. 3. Stuffing everything into a ``ApiClientConfig`` class and only providing that class? 4. Using ``@Property`` and providing everything as a properties map? 5. Not using Annotations for classes like this; instead injecting them via code in the main application where these various configurations/settings can be loaded? I've tried a few different ways over the months but they all seem somewhat messy and dissatisfactory. Any widsom to share? Preferable from larger codebases where this kind of mess might end up having a big impact on readability or reproducibility?
    👀 2
    a
    • 2
    • 3
  • j

    Jonathan

    09/09/2025, 2:37 PM
    I believe I have come up with a solution to this question here. Though, I’ve not been able to test it, yet. I’m following this guide to setup custom modules setup so that my platform (Android/iOS) specific sourceSet code gets picked up. I believe I have everything set correctly as I can KSP generated code in the
    commonMain/
    sourceSet. The concern I have is that “native” component scanning doesn’t seem to work. Reviewing the
    androidMain/
    generated code I don’t see Koin declarations for classes I’ve marked with`@Single` . The generated module for
    actual class NativeModule
    is empty. I don’t see one at all for
    iosMain/
    . Has anyone else experienced this? https://kotlinlang.slack.com/archives/C67HDJZ2N/p1757211546010449
    a
    • 2
    • 5
  • s

    Suresh Maidaragi

    09/15/2025, 7:16 AM
    hi there we are coming across
    slow cold start
    and anr issues due to koin initialisation on one of your project wherein we have 20modules out of which around 10 are in kmp, so when tries to initialise this 10 Kmp modules using koin, it takes around ~7sec to init and move to further screens. This modules are initialised within Application class. We already made all this koin init async still the issue persisting around. Is there work around this?? to make it initialise quicker/ondemand when we init this 10kmp module on demand during runtime we are seeing
    no koin def found issues
    a
    • 2
    • 9
  • k

    Karan Sharma

    09/16/2025, 12:40 PM
    Does the viewmodel instance gets cleared upon navigating to another screen?
    Copy code
    composable<SavedTripsRoute> { backStackEntry ->
        val viewModel: SavedTripsViewModel = koinViewModel<SavedTripsViewModel>(key = "SavedTripsNav")
    }
    Tried using a key, as well, but observed that when i navigate away and back to this screen,
    SavedTripsViewModel
    is recreated. koin - 4.1.1 nav compose - 2.9.0-rc02 compose-multiplatform = "1.9.0-rc02" happens for both ios and android.
    s
    a
    • 3
    • 10
  • k

    Kazik

    09/17/2025, 1:17 PM
    Is
    @InjectedParam
    be passed to another dependency which expect it with koin-annotations? For example I have following classes
    Copy code
    @Factory
    class TestSampleClass(
        @InjectedParam val name: String,
        val sample: AnotherSample
    ) {
        fun hello(): String {
            return "Hello $name!"
        }
    
        fun hello2(): String {
            return sample.hello()
        }
    }
    
    @Factory
    class AnotherSample(@InjectedParam val name: String) {
        fun hello(): String {
            return "Another $name!!!"
        }
    }
    When I injected for example like this it is possible to also
    AnotherSample
    class instantiated with that parameter?
    Copy code
    private val testSampleClass: TestSampleClass by inject { parametersOf("woooo!") }
    ✅ 1
    a
    • 2
    • 2
  • w

    WukongRework.exe

    09/23/2025, 8:05 AM
    hello everyone, currently running into a weird issue with Koin in a Compose multiplatform project. I have my DI set up with Koin using
    KoinMultiplatformApplication
    and have just set up deep linking. The initial prototype of the deep link is working fine on iOS but when testing on Android, an
    java.lang.IllegalStateException: KoinApplication has not been started
    error is thrown crashing the application. I’ve tried changing to using
    KoinApplication
    following https://carrion.dev/en/posts/koin-cmp/ as seen in the comments of https://github.com/InsertKoinIO/koin/issues/2157 to no change in the behavior, with the same illegal state exception. The tested Koin version is 4.1.1 The Compose version is 1.9.0 The full stack trace in 🧵 Thanks in advance!
    • 1
    • 1
  • g

    galex

    09/24/2025, 6:03 PM
    Hello, while using a custom named annotation
    @DefaultHttpClient
    I had no problem bringing a specific dependency in a constructor of a class:
    Copy code
    @Single
    internal class FirebaseAuthImpl(
        private val firebase: Firebase,
        private val firebaseSettings: Lazy<FirebaseSettings>,
        @param:DefaultHttpClient  val httpClient: Lazy<HttpClient>,
        private val json: Lazy<Json>,
    ) : FirebaseAuth { ... }
    Now, using the same annotation in a function misses the annotation:
    Copy code
    @Single
        fun provideFirebaseAuth(
            firebaseApp: FirebaseApp,
            firebaseSettings: Lazy<FirebaseSettings>,
            @DefaultHttpClient httpClient: Lazy<HttpClient>,
            json: Lazy<Json>,
        ): FirebaseAuth {
            return createFirebaseAuth(
                firebaseApp = firebaseApp,
                firebaseSettings = firebaseSettings,
                httpClient = httpClient,
                json = json,
            )
        }
    The error is the following:
    Copy code
    [ksp] --> Missing Definition for property 'httpClient : io.ktor.client.HttpClient' in 'com.domain.app.di.provideFirebaseAuth'. Fix your configuration: add definition annotation on the class.
    What am I missing? 🤔
    a
    • 2
    • 5
  • b

    Bobby Hargett

    09/25/2025, 12:04 PM
    If I have a module like this:
    Copy code
    @Module()
    @ComponentScan("com.hssw.wallpaperprude")
    class DefaultModule {
    
        @Single
        fun ucFetch() {
            val flow: SharedFlow<Async<RedditClient>> = get()
            val response = MutableSharedFlow<RedditUseCase?>(replay = 1).apply {
    How do I get the val "flow" from Koin? The @Single Flow is defined elsewhere in the module
    m
    • 2
    • 1
  • k

    Kyle Szalai

    10/01/2025, 2:39 PM
    hey! 👋 I'm having a hard time tracking down how to fix this issue I'm seeing I have an Android Compose module using Koin and I'm adding it to my main project. In my release variant, R8 seems to be removing
    androidx.core.bundle.Bundle
    , so it fails to build
    Copy code
    Missing class androidx.core.bundle.Bundle (referenced from: kotlin.jvm.functions.Function0 org.koin.viewmodel.BundleExtKt.emptyState() and 2 other contexts)
    I would assume I need to add some consumer proguard rules, so I am trying to add
    Copy code
    -keep class androidx.core.bundle.Bundle {}
    to my Proguard configuration, but this doesn't fix the issue. I've tried adding
    org.jetbrains.androidx.core
    to the project to see if providing it fixes it, but unfortunately, nothing. Koin 4.0.4 (
    koin-android
    and
    koin-androidx-compose
    ) Compose BOM 2024.04.00 Kotlin 2.1.20
    • 1
    • 1
  • a

    arnaud.giuliani

    10/07/2025, 1:23 PM
    Koin Annotations 2.2 is released with big new features 🎉 • JSR 330 Compat • Smart Configurations • Scope Archetypes Take a look 👇 https://medium.com/koin-developers/koin-annotations-2-2-jsr-330-compatibility-smart-configurations-and-scope-archetypes-5b2f4c8536c1
    nice spin 3
    🆒 2
    🎉 10
    👀 1
  • i

    Irsath Kareem

    10/10/2025, 3:04 AM
    Whether KSP Version (2.2.20-2.0.3) is supported by koin annotations 2.2 I see in Koin Annotations Documentation, that Latest KSP Support is 2.1.21-2.0.2 Whether I need KSP to be downgraded??????
    a
    • 2
    • 1
  • i

    Irsath Kareem

    10/10/2025, 4:39 AM
    One more: 1. Constructor provider Possible when using Koin Annotations a.
    singleOf(::DatabaseFactory)
    a
    • 2
    • 3
  • b

    bartek.t

    10/10/2025, 1:00 PM
    Do I understand RememberObserver correctly? Once I create a custom scope related to a navigation route and it’s placed in the back stack, will RememberObserver trigger the disposal of any custom scope created with the KoinScope() function?
    a
    • 2
    • 3
  • h

    Horatio Thomas

    10/12/2025, 5:00 AM
    Anyone know how you would get the ktor environment context in a ktor appModule?
  • f

    Farhazul Mullick

    10/15/2025, 9:56 AM
    Is Annotation based koin in koin 4.1 Compile time library like Hilt?
    a
    • 2
    • 4
  • m

    Mark

    10/15/2025, 1:04 PM
    I’m migrating as much androidMain code to commonMain as possible. I’m wondering about viewmodels associated with the
    MainActivity
    which I currently access using:
    Copy code
    inline fun <reified T : ViewModel> koinActivityViewModel(
        qualifier: Qualifier? = null,
        key: String? = null,
        scope: Scope = currentKoinScope(),
        noinline parameters: ParametersDefinition? = null,
    ): T = koinViewModel<T>(
        qualifier = qualifier,
        viewModelStoreOwner = LocalActivity.current as ComponentActivity,
        key = key,
        scope = scope,
        parameters = parameters,
    )
    Claude is recommending I just use
    single { }
    for such a view model. Thoughts?