koin-annotations
koin-annotations copied to clipboard
ComponentScan on object with Koin Annotated Methods Doesn't Work
Describe the bug
Adding @ComponentScan to an object annotated with @Module that contains annotated functions does not work. The package is not scanned for other annotated values (or if it is, they are overwritten by the ones provided in the body of the object). I did notice that if there is another module definition or a annotated class in a package external to the ComponentScan that the component scan works correctly.
To Reproduce Steps to reproduce the behavior: Declare module like this
@Module
@ComponentScan("com.example.somepackage")
object MyModule {
@Single
fun someSingleton(): Some3rdPartyType = Some3rdPartyType()
operator fun invoke() = this //needed because of something similar to https://github.com/InsertKoinIO/koin-annotations/issues/72
}
Declare this in another file in the com.example.somepackage package
@Single
Some1stPartyType(some3rdParty: Some3rdPartyType) {
}
Expected behavior Expected that component scan kicks in and picks up annotated types.
Koin project used and used version (please complete the following information): koin-annotations & koin-ksp-compiler 1.3.0
Additional moduleDefinition Object module declarations with declared annotated functions result in generated code that tries to call a non-existent constructor (but when it does not contain function declarations then the generated code does not try to call any constructor)
I'm having this same issue. Except I have the following error when the annotated @Module in question is a class MyModule and not just an object MyModule (seems that aspect isn't relevant here)
@arnaudgiuliani do you have any recommendations how we might address or work around this issue?
Interesting, I had the issue with it being an object, then it was resolved when it was made into a class. I will note that I was also having issues where I'd entirely removed a module and code was still being generated for it, but I was suspecting there was just something messed up with my project setup and stuff wasn't being cleaned properly.
can you seperate annotatations from object into a class? definition are detected on Kotlin classes for now.
I create an PR https://github.com/InsertKoinIO/koin-annotations/pull/107