Hi, I have problem with compile-time check. It say...
# koin
r
Hi, I have problem with compile-time check. It says
[ksp] --> Missing Definition type StarWarsApi for MyViewModel. Fix your configuration to define type StarWarsApi.
but if I turn off the check everythink compiles and the definition is injected properly.
Problem may be that, the
MyViewModel
is using Annotation
@Factory
and the injected Api is in different module and is provided with
single { }
method. But I thought that it can be used both manual and annotation based at the same time
Also where should I turn on the compile time check? Do I have to turn it on in every module? E.g I have
feature
and
network
modules.
feature
has viewmodels which uses api from
network
a
Problem may be that, the
MyViewModel
is using Annotation
@Factory
and the injected Api is in different module and is provided with
single { }
method. But I thought that it can be used both manual and annotation based at the same time
yes, Koin annotations compilation check covers annotated components only for now (still WIP)
Also where should I turn on the compile time check?
Do I have to turn it on in every module?
E.g I have
feature
and
network
modules.
feature
has viewmodels which uses api from
network
Good question, need to double check if you activate it in the main module is enough or not 🤔
r
Thanks for the reply, is there any timeframe for compile time check also for manually defined deps? Because I think I can't replace all
single { }
definitions by annotations. Or is there a secret to provide e.g.
httpClient
with annotations?
Copy code
single {
        HttpClient {
            install(ContentNegotiation) {
                json(json = get(named("restApiJson")), contentType = ContentType.Application.Json)
            }
            install(Logging) {
                this.level = <http://LogLevel.INFO|LogLevel.INFO>
                this.logger = KtorKermitLogger()
            }
        }
    }
a
you could annotate an inner module function:
Copy code
@Module
class MyModule {

    @Single
    fun httpClient() = HttpClient {
        install(ContentNegotiation) {
            json(json = get(named("restApiJson")), contentType = ContentType.Application.Json)
        }
        install(Logging) {
            this.level = <http://LogLevel.INFO|LogLevel.INFO>
            this.logger = KtorKermitLogger()
        }
    }
}
if you need a dependency, pass it as parameter of the function: https://insert-koin.io/docs/reference/koin-annotations/modules#definitions-in-class-modules
r
ok, looks neat. I got another challenge. ⬇️ these two definitions of modules should be equal, but with annotations it doesn't work because
ApolloClientFactory
is internal, is there some workaround this? the
internal
modifier is important for us as it is inside kmp shared module.
a
ha, the function can't work with such parameter?
r
it can't, because
ApolloClientFactory
is internal and it says it would expose it
a
how did you use it in DSL?
r
it is on the picture, I got it from koin using
get<ApolloClientFactory>
it's inside
single
lambda, can I somehow call
get()
inside body of
apolloClient
function?
a
really curious that it's complaining like that 🤔
if you have a chance to export a snippet, I could help more 👍
r
When I define the module "the old" way it doesn't complain, but if I try to define it with annotations it complainst that it exposes internal type
Factory looks like this
a
can you open an issue on Koin Annotations Github?
👍 1