I'm getting a compilation error trying to use the ...
# koin
i
I'm getting a compilation error trying to use the
declare { }
DSL from Koin Test documented here: https://doc.insert-koin.io/#/koin-test/testing?id=declaring-a-component-on-the-fly Here are the project sources: https://github.com/sdkotlin/sd-kotlin-talks/blob/16f05dfb7292dcfa87e5df1c5d92b06c66cadba1/di-with-koin/src/it/kotlin/org/sdkotlin/koin/it/hello/HelloModuleIT.kt#L81 I tried
single
, and
factory
as in the docs, but both result in a:
Unresolved reference. None of the following candidates is applicable because of receiver type mismatch...
I thought maybe it could be an issue with the fact that I was using an inline class (experimental) as the component type, but it fails to compile with a simple String type as well:
declare { single { "testing" } }
. Am I doing something wrong here, or should I file a GitHub issue? Koin and Koin Test 2.1.1.
a
doc is out of date :/
the API for declare is
Copy code
/**
     * Declare a component definition from the given instance
     * This result of declaring a single definition of type T, returning the given instance
     *
     * @param instance The instance you're declaring.
     * @param qualifier Qualifier for this declaration
     * @param secondaryTypes List of secondary bound types
     * @param override Allows to override a previous declaration of the same type (default to false).
     */
    fun <T : Any> declare(
            instance: T,
            qualifier: Qualifier? = null,
            secondaryTypes: List<KClass<*>>? = null,
            override: Boolean = false
    ) {
        _scopeRegistry.rootScope.declare(instance, qualifier, secondaryTypes, override)
    }
declare
declare directly an instance into Koin
i
Ah, okay, so the DSL is gone. I have a working example using the plain old function call, so good to go there: https://github.com/sdkotlin/sd-kotlin-talks/blob/16f05dfb7292dcfa87e5df1c5d92b06c66cadba1/di-with-koin/src/it/kotlin/org/sdkotlin/koin/it/hello/HelloModuleIT.kt#L63