On a side note, I was wondering if someone also co...
# koin
h
On a side note, I was wondering if someone also could shed some light regarding the correct approach to overcome the deprecation of
checkModules
. I was trying to following the documentation and I noticed that replacing the old validation
checkModules
with the new mechanism
verify()
it fails with the error: 🧵
🧵 1
Copy code
* ----- > Missing definition for '[field:'engine' - type:'io.ktor.client.engine.HttpClientEngine']' in definition '[Singleton: 'io.ktor.client.HttpClient',qualifier:myHttpClient]'.
- Fix your Koin configuration -
1- add missing definition for type 'io.ktor.client.engine.HttpClientEngine'. like: singleOf(::io.ktor.client.engine.HttpClientEngine)
or
2- else define injection for 'io.ktor.client.HttpClient' with:
module.verify(
    injections = injectedParameters(
        definition<io.ktor.client.HttpClient>(io.ktor.client.engine.HttpClientEngine::class)
    )
) Old Validation
Copy code
@Test
    fun checkAllModules() = checkModules {
        modules(
            httpClientModule,
            redisModule,
            serviceModule,
            useCaseModule
        )
New Validation
Copy code
@Test
    fun checkAllModules() {
        module {
            includes(
                httpClientModule,
                redisModule,
                serviceModule,
                useCaseModule
            )
        }.verify()
    }
o
I admit, I just blindly followed the suggestion of the error without understanding anything clearly…
Copy code
@Test
fun `verify network module`() {
    networkModule.verify(
        injections = injectedParameters(
            definition<HttpClient>(HttpClientEngine::class, HttpClientConfig::class),
        )
    )
}
I'm not sure this was the best thing to do or if it just hides error… At runtime my dependency graph is perfectly fine, but the test was failing 🤷
h
Thanks so much for jumping in Oliver. I actually tried fixing the resolution for those errors as well. However, it suggests adding
Copy code
injections = injectedParameters(
                definition<HttpClient>(io.ktor.client.engine.HttpClientEngine::class),
            )
Then if I re-run, it asks to add
Copy code
injections = injectedParameters(
                definition<HttpClient>(io.ktor.client.HttpClientConfig::class),
            )
Then, after re-run asks me to re-add the first one again (which seems to be overridden). That's why I'm super confused
I'll double-check
Copy code
@Test
    fun checkAllModules() {
        module {
            includes(
                httpClientModule,
                redisModule,
                serviceModule,
                useCaseModule
            )
        }.verify(
            injections = injectedParameters(
                definition<HttpClient>(HttpClientEngine::class, HttpClientConfig::class),
                definition<TokenatorRedisClient>(io.lettuce.core.RedisClient::class)
            )
        )
    }
This seems to have fixed the issue indeed. I reckon I don't understand this much. 🤦🏽
o
Is it the same or another? The first time, I had
HttpClientEngine::class
, the second time once added it, I then had
HttpClientConfig::class
, leading to add both classes to the
definition
call.
h
I think the problem I had before was that I was injecting them separetly, like that: This is wrong
Copy code
injections = injectedParameters(
                definition<HttpClient>(io.ktor.client.engine.HttpClientEngine::class),
                definition<HttpClient>(io.ktor.client.HttpClientConfig::class),
            )
a
I've got the same issue, somehow verify picks up the wrong constructor
+ the issue so it has higher prio
a
will look at it 👍
🙌🏽 1