https://kotlinlang.org logo
Join Slack
Powered by
# koin
  • 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
    • 14
  • k

    Kazik

    07/01/2025, 9:58 AM
    Hello, does koin support feature similar to dagger/hilt like injecting all classes of the same interface. I try to achieve this using koin-annotations, but ksp fails to provide set of dependencies with error about missing definition for property. What I am missing here?
    Copy code
    interface RequestParser
    
    @Single
    class AImpl : RequestParser
    
    @Single
    class BImpl : RequestParser
    
    @Single
    class Repository(private val parsers: Set<RequestParser>)
    👀 2
    k
    j
    • 3
    • 7
  • e

    Eugen Martynov

    07/01/2025, 3:39 PM
    I'm trying to update to Koin 4.1.0 and my test of graph is failing with
    java.lang.IllegalStateException: Wrong Scope qualifier: trying to open instance ...
    👀 1
    k
    a
    • 3
    • 3
  • e

    Eugen Martynov

    07/01/2025, 3:39 PM
    How to troubleshot it?
  • r

    Roger Kreienbühl

    07/07/2025, 5:48 AM
    Hi I am rather new to dipendency injection with koin and koin-annotations. I have a kmp project with a ktor server and iOS and Android apps. the base setup works fine. Now I tried to define a class inside the shared gradle module and annotate it with
    @Single
    :
    Copy code
    package com.example.data.mapper
    import org.koin.core.annotation.Single
    
    @Single
    class XyzDtoMapper {
    ...
    }
    I try to scan for this class with a module defined inside the server gradle module:
    Copy code
    package com.example.di
    
    import org.koin.core.annotation.ComponentScan
    import org.koin.core.annotation.Module
    
    @Module
    @ComponentScan("com.example.data.mapper")
    class MapperModule
    Is such a Scan over multiple gradle modules possible, and if do, how can I achieve this? The Mapper module is generated but the
    XyzDtoMapper
    is not present in it.
    k
    m
    • 3
    • 7
  • s

    Suresh Maidaragi

    07/08/2025, 9:14 AM
    can someone help me to know is
    koinInject<xx-viewmodel>()
    is composable lifecycle aware?
    s
    a
    • 3
    • 10
  • r

    reactormonk

    07/08/2025, 4:08 PM
    We've got some code which contains mutable references, so we gotta create a new object on each invocation. Currently said object is created by Koin via regular
    get()
    , but then the injected code reuses the implementation. Can I somehow forward the injection to the actual call site, so an object is being created on each invocation?
    s
    • 2
    • 5
  • f

    FlowFan

    07/15/2025, 2:31 AM
    For dependencies that need to be instantiated in native code (like in Swift) and then injected into our shared Kotlin module, can this be handled with
    koin-annotations
    ?
    Copy code
    // commonMain
    interface GenerativeModel {
        suspend fun generateTextContent(prompt: String): String?
        suspend fun generateJsonContent(prompt: String): String?
        suspend fun generateImage(prompt: String): ByteArray?
    }
    // iosMain
    fun initialiseKoin(generativeModel: GenerativeModel) {
        startKoin {
            modules(
                module { single<GenerativeModel> { generativeModel } }
            )
        }
    }
    // swift
    @main
    struct iOSApp: App {
        init() {
            initialiseKoin(generativeModel: GenerativeModelIOS())
        }
    }
    p
    a
    f
    • 4
    • 6
  • a

    arnaud.giuliani

    07/17/2025, 7:45 AM
    For those who wants to take a look, I've fixed 4.1 closed scope issue in Compose - it's available in
    4.1.1-Beta1
    https://github.com/InsertKoinIO/koin/pull/2249
  • t

    Thierry Kh

    07/17/2025, 12:48 PM
    Hey guys. Noob question. How are we supposed to inject a dependency in a Wasm or Js main.kt ? I've never needed to do it before. The following doesn't seem to work :
    Copy code
    val getSomeUseCase: GetSomeUseCase = getKoin().get()
    Or it should be working but i need to fix something.
    a
    • 2
    • 5
  • p

    Pedro Francisco de Sousa Neto

    07/22/2025, 12:40 AM
    #koin-annotations Hey folks, do I need to do anything extra to use
    SavedStateHandle
    in a
    @KoinViewModel
    injected in a
    composable
    function? Version
    Copy code
    koin-bom = "4.1.0"
    koin-annotations = "2.1.0"
    kotzilla = "1.2.0-Beta1"
    kotzillaPlugin = "1.2.0-Beta2"
    Caused by: org.koin.core.error.NoDefinitionFoundException: No definition found for type 'androidx.lifecycle.SavedStateHandle'. Check your Modules configuration and add missing type and/or qualifier!
    When I remove the
    SavedStateHandle
    from my ViewModel, everything works fine.
    ✅ 1
    k
    a
    • 3
    • 7
  • p

    Pedro Francisco de Sousa Neto

    07/23/2025, 6:15 PM
    Hello again, folks. I'm running a study project in Kotzilla Platform. It's a fresh created project. And I'm very curious in how I can speed up my
    ViewModel
    intialization. I've shared my
    ViewModel
    constructor above. And now I'm sharing the other dependencies. GetUsers.kt
    Copy code
    @Factory
    class GetUsers(
        private val dao: UserDao
    )
    AppModule.kt
    Copy code
    @Module
    @ComponentScan("br.com.velantasistemas.mymoney")
    class AppModule {
    
        @Single
        fun getAppDatabase(): AppDatabase {
            return get(AppDatabase::class.java)
        }
    
        @Single
        fun getUserDao(): UserDao {
            return getAppDatabase().userDao()
        }
    }
    DatabaseModule.kt
    Copy code
    object DatabaseModule {
        val module = module {
            single<AppDatabase> {
                val context: Context = get()
                return@single Room.databaseBuilder(
                    context,
                    AppDatabase::class.java, "database-name"
                )
                    .allowMainThreadQueries()
                    .fallbackToDestructiveMigration(dropAllTables = true)
                    .build()
            }
        }
    }
    Questions: 1. How can I speed this up? 2. Could
    allowMainThreadQueries
    be the reason for this slowdown?
    3. Do you think this is a good way to handle database and DAO access? a. I know it's a matter of preference, but I'd really like to hear your thoughts, folks. 4. I remember using Koin's suspend initialization before. a. Does it help only during app startup, or could it also be beneficial for initializing singletons like the database in this case?
    k
    a
    • 3
    • 6
  • l

    Laurent Thiebaud

    07/24/2025, 9:15 AM
    Hi folks I have multiple junit tests based on koin Any idea how I could easily run tests in parallel? Looks like koin has a global context, and tests are not isolated (changing the junit config, I got errors like "koin already started")
    w
    a
    • 3
    • 5
  • o

    Osnir Mesquita

    07/28/2025, 9:15 PM
    Hey Guys! Is there a way to get a list of instances of a type based on a specific qualifier in Koin annotation? The getAll works to retrieve all instances, but I wanna get only one qualifier.
    w
    p
    • 3
    • 2
  • l

    Laurent Thiebaud

    07/30/2025, 3:05 PM
    Hi Using
    koinApplication
    , I inject some services within (using
    single
    and
    declare
    ) On runtime I inject other services using by
    inject<...>()
    Then when injected service is resolved, I have error
    KoinApplication has not been started
    It seems it tries to resolve other services using the global context Should I inject other services always using the
    koinApplication
    instance? (if so this is extremely boring) (this is next to my other question here)
    a
    • 2
    • 1
  • j

    Jonathan

    07/31/2025, 6:37 PM
    I'm having trouble w/ writing unit test for a library that uses Isolated Context. It appears that previous values are retained between different test functions. What is the recommend way to restart an Isolated Context at the start of each test so that it's in an unloaded state.
    a
    • 2
    • 1
  • a

    ABRAR WIRYAWAN

    08/07/2025, 3:56 AM
    hi, i have question regarding Koin usage in benchmark related thing, like macrobenchmark and baseline profile. Is there any guide to inject custom dependencies for benchmark test or is it the same like standard UI test?
    👀 1
    a
    • 2
    • 2
  • e

    Edgar Avuzi

    08/08/2025, 3:10 AM
    Hi all. Can you please confirm that there is currently no official support for using Koin annotations with Maven (only the DSL works), and that the only way to use annotations is via Gradle? https://insert-koin.io/docs/reference/koin-annotations/start/ I need Koin annotations for my Maven Kotlin JVM backend
    👀 1
    k
    a
    m
    • 4
    • 9
  • a

    Abhimanyu

    08/08/2025, 5:37 PM
    Hi all 👋 , How to write integration tests for application using Koin? I am getting the following error when running my tests.
    Copy code
    java.lang.IllegalStateException: KoinApplication has not been started
    solved 1
    • 1
    • 5
  • p

    Pedro Francisco de Sousa Neto

    08/09/2025, 2:45 PM
    https://github.com/InsertKoinIO/koin-embedded Hey folks, with this project, could I run two different Koin versions simultaneously? Like a traditional one (2.x) and a new one repackaged as 4.x. 🤔
    k
    • 2
    • 1
  • p

    Pedro Francisco de Sousa Neto

    08/12/2025, 12:03 AM
    Suggestions for Improving the Koin Documentation A few days ago, I spoke with Mey and @Olwethu PISSOT. I was supposed to compile some suggestions for improvements to the Koin documentation. I’m sharing them in a PDF file, but please consider this an open thread for anyone to add more suggestions in this regard. And of course, some inputs are personal, so these ideas are not set in stone. 😉
    🙏🏾 1
    👏 3
    o
    • 2
    • 1
  • a

    Alexey

    08/12/2025, 4:09 AM
    hello! I try create 2 datastore in kmp with koin, this code not working, app crash with error: ava.lang.ClassCastException: ProfileDto cannot be cast to SettingsDto
    Copy code
    actual val dataStoreModule: Module = module {
        single {
            createProfileDataStore {
                createAndroidFilePath(get(), "profile.json")
            }
        }
        single {
            createSettingsDataStore {
                createAndroidFilePath(get(), "settings.json")
            }
        }
    }
    But if i add named, all works good, it good practice, or u have better way for provide 2 different datastore in kmp? In hilt(android native) works good without named param
    Copy code
    enum class DataStoreType {
        Profile,
        Settings
    }
    
    actual val datastoreModule: Module = module {
        single<DataStore<ProfileDto>>(
            named(DataStoreTypes.Profile)
        ) {
            createProfileDataStore {
                createAndroidFilePath(get(), "profile.json")
            }
        }
        single<DataStore<SettingsDto>>(
            named(DataStoreTypes.Settings)
        ) {
            createTokensDataStore {
                createAndroidFilePath(get(), "settings.json")
            }
        }
    }