Does anybody has any workaround for this issue: <h...
# koin
p
Does anybody has any workaround for this issue: https://github.com/InsertKoinIO/koin/issues/1353 ?
a
what are you doing to be in this case?
parameters injection?
p
I’m trying to retrieve parameterised instances from Koin.
a
something like
single { myParams -> MyInstance(myParams) }
?
p
Already doing this in my modules file. My code structure (vaguely) is as follows:
Copy code
serviceModule.kt:

fun serviceModule() = module {
	factory { (param: MyParam) -> Service(param)) }
}

koin.kt:

fun Application.configureKoin() {
    install(Koin) {
        SLF4JLogger()
        modules(
            serviceModule(),
            /* other modules */
        )
    }
}

service.kt:

fun doSomething(callParam: Param): Either<Throwable, String> = Either.catch {
    val service: Service =
        injectByComponent { parametersOf(param) }
    service.doStuff()
}

utils.kt:

inline fun <reified T> injectByComponent(
    noinline parameters: ParametersDefinition? = null
): T {
    return object : KoinComponent {
        val value: T by inject(parameters = parameters)
    }.value
}
Using this, I’m getting the same error as other people are getting:
java.lang.IllegalStateException: Deque is too big.
and
ArrayDeque is empty.
The only difference is that they are using
get()
to fetch instance and I’m using
by inject()
a
yeah, seems parameters are not clearing the stack once called 🤔
n
It could be related to concurrent issues with parameters injection. I feel that https://github.com/InsertKoinIO/koin/pull/1465 might fix the issue. If I remember I did reproduce it in the tests without the fix. It would definitely help if someone checked this PR to see if we're into something, since the test could be a reproducer.