Michael Friend
05/14/2025, 9:52 PMapiModule
and trying to inject an instance of AuthProvider
in but i get a NoDefinitionFoundException
on startup because its trying to get an instance of AuthProvider
while build the dependency tree rather than lazily when an instance of MyApi
is requested. I know i can move the get()
call down into apiModule
and have it just assume any callers will provide that in their own koin definitions, but id rather that dependency be more explicit
// An api module that can expects an AuthProvider to handle requests
val apiModule(authProvider: AuthProvider) = module { single { MyApi(authProvider) }
// In my apps start up
startKoin {
modules(appModule(), apiModule(get())) // Cant get the instance from Koin here since it evaluates it eagerly before appmodule is setup
}
fun appModule() = module {
single<AuthProvider> { AppAuthProvider() }
}
Michael Friend
05/14/2025, 9:57 PMfun appModule() = module {
single { MyApi(authProvider = get()) }
}
// In my apps start up
startKoin {
modules(appModule(), apiModule()) // Auth provider is provided implicitly
}
fun appModule() = module {
single<AuthProvider> { AppAuthProvider() }
}
withoutclass
05/15/2025, 2:20 PMsealed class ApiModuleQualifiedConfiguration {
object AuthProvider : ApiQualifiedConfiguration()
}
sealed class ApiModuleQualifiedDependency {
object ApiService : ApiModuleQualifiedDependency()
}
withoutclass
05/15/2025, 2:21 PM