Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ComponentScan on object with Koin Annotated Methods Doesn't Work #98

Open
undermark5 opened this issue Nov 8, 2023 · 5 comments
Open
Labels
question Further information is requested status:checking Ticket is currently being checked

Comments

@undermark5
Copy link

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)

@agopinath-ap
Copy link

agopinath-ap commented Nov 17, 2023

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)

@agopinath-ap
Copy link

@arnaudgiuliani do you have any recommendations how we might address or work around this issue?

@undermark5
Copy link
Author

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.

@arnaudgiuliani
Copy link
Member

can you seperate annotatations from object into a class? definition are detected on Kotlin classes for now.

@arnaudgiuliani arnaudgiuliani added question Further information is requested status:checking Ticket is currently being checked labels Nov 27, 2023
@ghasemdev
Copy link
Contributor

I create an PR #107

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested status:checking Ticket is currently being checked
Projects
None yet
Development

No branches or pull requests

4 participants