Joost Klitsie
03/15/2026, 7:18 PM@Factory
class MyClass(@Provided private val myInterface: MyInterface)
Instead, I get [Koin] Missing dependency MyInterface
If I turn off the compile check (compileSafety.set(false) ) then my app compiles and runs just fine.
I see here https://github.com/InsertKoinIO/koin-compiler-plugin/releases something on the @Provided annotation and if I try to mark my interface with @Provided, I get the same error. Also, if it would be an external dependency, how can you mark it as @Provided if it is a third party class?
// example from github
@Provided
class ExternalService // provided by framework at runtime
@Singleton
class MyService(val ext: ExternalService) // no errorJoost Klitsie
03/15/2026, 7:36 PM// in gradle module b
@Module(includes = [ModuleA::class])
class ModuleB
// in gradle module c
@Module(includes = [ModuleB::class])
class ModuleC
No error:
// in gradle module b
@Module(includes = [ModuleA::class])
class ModuleB
// in gradle module c
@Module(includes = [ModuleA::class, ModuleB::class])
class ModuleC
This would force me to make all modules depend on each other, which I would wish to avoid.Alexandru Caraus
03/25/2026, 4:22 AMJoost Klitsie
03/25/2026, 2:23 PMAlexandru Caraus
03/26/2026, 4:58 AMJoost Klitsie
03/26/2026, 8:31 AMJoost Klitsie
03/26/2026, 8:33 AMAlexandru Caraus
03/26/2026, 9:13 AMJoost Klitsie
03/26/2026, 9:22 AMAlexandru Caraus
03/26/2026, 10:31 AMAlexandru Caraus
03/26/2026, 10:32 AMAnastasios Georgousakis
04/04/2026, 1:12 PM// lib/src/main/kotlin/MyLib.kt
package com.example.mylib
import org.koin.core.annotation.ComponentScan
import org.koin.core.annotation.Module
import org.koin.core.annotation.Provided
import org.koin.core.annotation.Single
@Module
@ComponentScan("com.example.mylib")
class LibModule
interface ExternalService {
fun doSomething()
}
@Single
class MyService(@Provided val externalService: ExternalService) {
fun doSomething() {
externalService.doSomething()
}
}
and the following koin application
// app/src/main/kotlin/MyApp.kt
package com.example.myapp
import com.example.mylib.ExternalService
import com.example.mylib.LibModule
import com.example.mylib.MyService
import org.koin.core.annotation.ComponentScan
import org.koin.core.annotation.Configuration
import org.koin.core.annotation.KoinApplication
import org.koin.core.annotation.Module
import org.koin.core.annotation.Single
import org.koin.plugin.module.dsl.startKoin
//@Single
class MyExternalService: ExternalService {
override fun doSomething() {
println("Hello from MyExternalService")
}
}
@Module(includes = [LibModule::class])
@ComponentScan("com.example.myapp")
@Configuration
class AppModule
@KoinApplication
object MyApp
fun main() {
val app = startKoin<MyApp>()
val service = app.koin.get<MyService>()
service.doSomething()
}
if I comment or forget to put@Single in MyExternalService I will not get any compile error and when I run the application I will get the following error
Caused by: org.koin.core.error.NoDefinitionFoundException: No definition found for type 'com.example.mylib.ExternalService' on scope '['_root_']'.. Check or add definition for type 'com.example.mylib.ExternalService' in scope '_root_'.Anastasios Georgousakis
04/04/2026, 1:24 PMclass ModuleTest {
@Test
fun checkKoinModule() {
LibModule().module.verify(
extraTypes = listOf(
ExternalService::class
),
)
}
}
which was match better because we didn't have to anotate all our ExternalService declarations with @Provided
It woud be better if we could have this extraTypes inside @Module annotation and koin compiler avoid to try to find this classes when it compiles the module, but do a full check when you have a startKoin somewherearnaud.giuliani
04/13/2026, 2:51 PMAnastasios Georgousakis
04/15/2026, 11:18 AM@Single
class ProjectDefaultService(
private val i18n: MessageResolver,
private val projectRepository: ProjectRepository,
private val userService: UserService,
private val formService: FormService,
private val organizationService: OrganizationService,
private val organizationAssociateService: OrganizationAssociateService,
private val stateFlowService: StateFlowService,
private val cacheManager: CacheManager,
private val entityUpdateEventPublisher: EntityUpdateEventPublisher,
@Property("namespace")
private val namespace: String,
) : ProjectService {
// implementation here
}
now with koin compiler in order to have compile safety I have to change them to this
@Single
class ProjectDefaultService(
@Provided private val i18n: MessageResolver,
private val projectRepository: ProjectRepository,
@Provided private val userService: UserService,
@Provided private val formService: FormService,
@Provided private val organizationService: OrganizationService,
@Provided private val organizationAssociateService: OrganizationAssociateService,
@Provided private val stateFlowService: StateFlowService,
@Provided private val cacheManager: CacheManager,
@Provided private val entityUpdateEventPublisher: EntityUpdateEventPublisher,
@Property("namespace")
private val namespace: String,
) : ProjectService {
// implementation here
}
Most of dependencies are interfaces and the implementation is in another module. Also, there are two different modules for each service implementation, one using repository to read/write data from database and one using rest client to read/write data from a another microservice. So, depending which mode I want to deploy my application I can choose which module will implement each service. If you want to have a clean architecture @Provided annotation does not help. You don't want your interfaces to depend in any framework (Spring or Koin) so adding specific framework annotations in your interfaces is not ideal solution. I would better if we could define the extra types in the module dsl or @Module class. This class is created only for koin framework and we can have anything relevant to koin their.arnaud.giuliani
04/16/2026, 3:30 PM