Hi! I have a problem with using annotations on fun...
# koin
p
Hi! I have a problem with using annotations on functions that have a few parameters of the same type. I tried to used
named
and
property
but that does not work.
Copy code
@Single
    @Named("httpLoggingInterceptor")
    fun provideLoggingInterceptor(): Interceptor =
        HttpLoggingInterceptor().apply {
            level = HttpLoggingInterceptor.Level.BODY
        }

    @Single
    @Named("myOkHttpClient")
    fun providePublicHttpClient(
        authenticator: Authenticator,
        @Property("addHeadersInterceptor") addHeadersInterceptor: Interceptor,
        @Property("httpLoggingInterceptor") logInterceptor: Interceptor,
        @Property("forbiddenInterceptor") forbiddenInterceptor: Interceptor
    ): OkHttpClient =
The generated code in the thread 🧵
generated code:
Copy code
single(qualifier=org.koin.core.qualifier.StringQualifier("myOkHttpClient")) { _ -> myapp.android.di.NetworkModule.providePublicHttpClient(authenticator=get(),getProperty("addHeadersInterceptor"),getProperty("httpLoggingInterceptor"),getProperty("forbiddenInterceptor")) } bind(okhttp3.OkHttpClient::class)
I guess the generated code should use
getParam
, but the annotation
InjectedParam
does not have the name parameter for quialifier, so I cannot use 3 interceptors
a
Change the @Property to @Named
Not sure what property does
And @InjectedParam is not injected, its left for you to pass manually the dependency
The object is partialy created with the injected param left out to be populated at later time
p
Got it to work with named, however that was not clear for me when reading documentation for annotations.
👍 1