https://kotlinlang.org logo
#koin
Title
# koin
r

rudolf.hladik

11/06/2023, 1:50 PM
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

arnaud.giuliani

11/08/2023, 8:51 AM
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

rudolf.hladik

11/09/2023, 2:44 PM
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

arnaud.giuliani

11/09/2023, 3:24 PM
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

rudolf.hladik

11/10/2023, 8:27 AM
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

arnaud.giuliani

11/10/2023, 1:31 PM
ha, the function can't work with such parameter?
r

rudolf.hladik

11/10/2023, 1:50 PM
it can't, because
ApolloClientFactory
is internal and it says it would expose it
a

arnaud.giuliani

11/10/2023, 2:00 PM
how did you use it in DSL?
r

rudolf.hladik

11/10/2023, 2:04 PM
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

arnaud.giuliani

11/10/2023, 2:40 PM
really curious that it's complaining like that 🤔
if you have a chance to export a snippet, I could help more 👍
r

rudolf.hladik

11/14/2023, 8:55 AM
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

arnaud.giuliani

11/14/2023, 9:17 AM
can you open an issue on Koin Annotations Github?
👍 1
2 Views