https://kotlinlang.org logo
Join Slack
Powered by
# koin
  • 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
    b
    • 3
    • 25
  • 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?
    a
    • 2
    • 2
  • 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?
    s
    a
    • 3
    • 18
  • s

    Shahid Iqbal4213

    10/18/2025, 5:31 PM
    Hey team i'm facing strange issue when using name qualifier can someone tell whats wrong here and how can i set? Koin Version 4.1.1 Issue: _Type is not declared in Koin modules: retrofit2.Retrofit (auth_retrofit)_
    Copy code
    internal val authApiModule = module {
        single<Retrofit>(named(AUTH_RETROFIT_QUALIFIER)) {
            Retrofit.Builder()
                .baseUrl("<https://api.example.com/>") // Base URL must be set here
                .addConverterFactory(GsonConverterFactory.create())
                .client(get<OkHttpClient>(qualifier = named(OKHTTP_CLIENT_QUALIFIER)))
                .build()
        }
    
        factory<AuthApi> {
            provideApi(
                get<Retrofit>(qualifier = named(AUTH_RETROFIT_QUALIFIER)),
                AuthApi::class.java
            )
        }
    }
    and AuthApi module is added to main module
    Copy code
    val authFeatureModule = module {
    
        includes(authNavModule, authApiModule, authMainModule)
    }
    a
    • 2
    • 1
  • i

    Irsath Kareem

    10/19/2025, 8:20 AM
    When using Koin Annotations 2.2.x This is the basic multi module setup, :app --> featurepresentation --> featuredomain <--impl-- featuredata
    @KoinApplication
    is available in
    :app
    module, (it looks for @Configuration in its direct child modules) Let's assume, I want to write
    @Configuration("test")
    in
    :feature:data
    module. (which needs to load only in tests.) This configuration is automatically loaded by
    :app
    module's
    @KoinApplication(config... = ["test"])
    ????? I think, Currently, It is not. Can you help me?, Or any other workaround???
    a
    • 2
    • 4
  • o

    Otávio Gabriel (Tavieto)

    10/20/2025, 7:08 PM
    Hello everyone! I'm needing some help related to tests with Koin. What's the main difference between the old and now deprecated
    checkModules
    to the new
    verify
    ? Because I'm seeing some scenarios where verify should fail, but it's not failing. Maybe I'm getting something wrong. If not, I would like to contribute to the project.
    a
    • 2
    • 8
  • a

    arnaud.giuliani

    10/22/2025, 7:28 AM
    I'm starting to align the Koin ecosystem on Kotlin 2.2.x Here is Koin Annotations 2.3 track, using latest KSP & Kotlin 2.2.20 - https://github.com/InsertKoinIO/koin-annotations/releases/tag/2.3.0
    🎉 5
  • o

    Otávio Gabriel (Tavieto)

    10/22/2025, 11:34 PM
    I have answered an issue on github and wasn't really an issue, just a misunderstanding. In that case, should I report to someone to close the issue?
    p
    • 2
    • 2
  • f

    FlowFan

    10/23/2025, 4:01 AM
    When upgrading koin-annotations from 2.1.0 to 2.3.0, how should Koin be initialized? Here is my previous multiplatform entry code, which now fails to compile with "Unresolved reference 'defaultModule'". Also, I would like to ask if there is a new way to initialize Koin for multiplatform in the new version, such as using annotations?
    Copy code
    @Composable
    @Preview
    fun App(
        modifier: Modifier = Modifier,
        darkTheme: Boolean = isSystemInDarkTheme(),
        navController: NavHostController = rememberNavController()
    ) {
        KoinApplication(
            application = {
                modules(AppModule.module)
                defaultModule()
            }
        ) {
            MainScreen(navController = navController)
        }
    }
  • c

    Chirag Redij

    10/25/2025, 12:50 PM
    Out of no where I am getting this issue
    Copy code
    Package 'core.data' was compiled by a pre-release version of Kotlin and cannot be loaded by this version of the compiler.
    Here are my Kotlin versions
    Copy code
    kotlin = "2.2.20"
    ksp = "2.2.20-2.0.4"
    Koin versions
    Copy code
    koin-core = "4.1.1"
    koin-annotation = "2.3.0"
    a
    • 2
    • 1
  • d

    Denys

    10/27/2025, 2:32 PM
    Could you please tell me how to use Koin in an isolated context in my SDK?
    a
    • 2
    • 2
  • a

    arnaud.giuliani

    11/05/2025, 4:46 PM
    Hello all đź‘‹ we have some KSP2 breaking with Koin Annotations for KMP apps. I'm looking for help on it: https://github.com/InsertKoinIO/koin-annotations/issues/317
    👍 2
  • a

    arnaud.giuliani

    11/05/2025, 4:47 PM
    for KMP apps users, you can continue with KSP 2.1.20. Android users are not impacted
  • b

    Bart

    11/05/2025, 7:51 PM
    Is it possible to use
    @KoinApplication
    in other source set than
    commonMain
    (e.g.
    commonTest
    or custom)? I have custom source set for instrumented tests (it includes
    commonMain
    like
    commonTest
    does), and
    @KoinApplication
    when used in this source set not generated the code properly, needed to put it in
    commonMain
    . Would be useful/cleaner is such test koin application could be created in test source set.
  • a

    Anuta Vlad Sv

    11/06/2025, 9:59 AM
    Hi! I'm using KoinStartup in a KMP project, but my StartupBenchmarks show it actually made cold start slightly slower, not faster. I'm using io.insert-koinkoin androidx startup4.1.1 My theory: Deep, tangled dependency chains are the root cause. Even though KoinStartup runs earlier in the process, all 15+ modules are still created synchronously on the main thread because they depend on each other — no real lazy loading happens. What’s the right strategy to break this cycle and actually improve startup time?
  • m

    Michal Klimczak

    11/06/2025, 10:24 AM
    Any ideas why this stops working when migrating from 1.4.0 to 2? Tried a few different 2+ versions, currently 4.1.1 + 2.2.0. KMP project
  • p

    Pedro Francisco de Sousa Neto

    11/06/2025, 12:17 PM
    Hi! I'm trying to migrate from AndroidX Navigation in a KMP project to Koin Navigation (using modules etc, version 4.2.0-alpha1). I've implemented in common dependencies:
    Copy code
    // build.gradle.kts
    implementation(libs.koin.core)
    implementation(libs.koin.core.coroutines)
    implementation(libs.koin.compose)
    implementation(libs.koin.compose.viewmodel)
    implementation(libs.koin.compose.viewmodel.navigation)
    implementation(libs.koin.compose.navigation)
    
    // libs.versions.toml
    koin = "4.2.0-alpha1"
    koin-compose = { module = "io.insert-koin:koin-compose", version.ref = "koin" }
    koin-compose-viewmodel = { module = "io.insert-koin:koin-compose-viewmodel", version.ref = "koin" }
    koin-compose-viewmodel-navigation = { module = "io.insert-koin:koin-compose-viewmodel-navigation", version.ref = "koin" }
    koin-compose-navigation = { module = "io.insert-koin:koin-compose-navigation3", version.ref = "koin" }
    koin-core = { module = "io.insert-koin:koin-core", version.ref = "koin" }
    koin-core-coroutines = { module = "io.insert-koin:koin-core-coroutines", version.ref = "koin" }
    koin-android = { module = "io.insert-koin:koin-android", version.ref = "koin" }
    I couldn´t find the import for
    NavigationHost
    in a
    @Composable
    function. What am I missing?
    🔥 1
    a
    • 2
    • 1