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

Angga Ardinata

02/29/2024, 4:53 AM
Hey everyone .. im new to Koin Annotations .. im planning on migrate my project to use annotations .. im heavily using multi module achitecture libraries for every feature and microservice .. and all those modules is compiled to AppModule I have a scenario like this .. I used to instantiate a Ktorfit module on AppModule/Parent module .. like this ..
Copy code
val ktorfitModule = module {
    single<Ktorfit> {
        ktorfit {
        // my config
        }
    }
}
then i used the ktorfit singleton in my child/service module like this
Copy code
single<AuthService> {
        val ktorfit : Ktorfit = get()
        ktorfit.create()
    }
and it works and compiled without any issue .. but when i try to do with annotations AppModule
Copy code
@Module(includes = [ServiceAuthModule::class])
@ComponentScan("com.ft.ats")
class AppModule {
    @Single
    fun getKtorfit(): Ktorfit {
        return ktorfit {
            // my config
        }
    }
}
Service Module
Copy code
@Module
@ComponentScan("com.ats")
class ServiceAuthModule {
    @Single
    fun authService(ktorfit: Ktorfit) : AuthService = ktorfit.create()

    @Single
    fun getRepository(service: AuthService) : AuthRepository = AuthRepositoryImpl(service)
}
now its not compiled .. im using this method both with Hilt and koin dsl without annotations and it has no problem .. what am i missing ?
Seems like it works if i turn the koin_check off .. but i want to have compile checking feature
p

Pedro Francisco de Sousa Neto

02/29/2024, 2:13 PM
In the KSP compile safety verification, what is the error? I didn't get it.
a

Angga Ardinata

02/29/2024, 2:16 PM
Ktorfit instance is not created or not found in auth service lib/module .. eventho i already create a singleton in appModule
p

Pedro Francisco de Sousa Neto

02/29/2024, 2:21 PM
Did you load the module in your
startKoin
? Something like:
startKoin { modules(ServiceAuthModule().module) }
a

Angga Ardinata

02/29/2024, 2:22 PM
I already try it .. i also try to include the servicemodule into AppModule
a

arnaud.giuliani

03/05/2024, 11:12 AM
what is not found by the KSP check?
a

Angga Ardinata

03/06/2024, 9:33 AM
the abstraction of the ktorfit interface i defined in AppModule
a

arnaud.giuliani

03/08/2024, 8:47 AM
is the type created inside Koin?
perhaps you have missed something in your config
same 1
3 Views