InsertKoinIO / koin-annotations

Koin Annotations - About Koin - a pragmatic lightweight dependency injection framework for Kotlin & Kotlin Multiplatform insert-koin.io
https://insert-koin.io
Apache License 2.0
163 stars 44 forks source link

Compile check with multi module setup. #103

Open extmkv opened 11 months ago

extmkv commented 11 months ago

Describe the bug Our project has 90+ modules, where 38 use Koin. After finishing the migration to Koin Annotations, we enabled the flag in all modules, and an issue arises when a module requires a dependency provided in another one, causing it to fail.

To Reproduce Lets take into consideration a project with 3 library modules + 1 app module.

  • Module A: Domain module
  • Module B: Implements some interfaces from Module A and register on Koin
  • Module C: It's a feature an needs to get some stuff from Koin.

Module A This module contains an interface Foo.

Module B Has an implementation of Foo called Bar

@Single
internal fun provideFoobar() : Foo {
     return Bar()
}

Module C

@Factory
internal fun provideMyFactory(
    foo: Foo
) : MyFactoryObject {
     return MyFactory.build(too)
}

App

 startKoin {
            androidLogger(Level.ERROR)
            androidContext(this@TrilogyApp)
            modules(listOf(ModuleA().module, ModuleB().module))
        }

Error

e: [ksp] --> Missing Definition type 'com.example.Foo' for 'com.example.b.provideMyFactory'. Fix your configuration to define type 'Foo'.

I'm gonna create a repository with a similar setup.

rodrirepresa commented 11 months ago

Here is a repo to reproduce @extmkv issue: https://github.com/rodrirepresa/koinannotationissue

extmkv commented 10 months ago

@arnaudgiuliani do you have any insights or idea how we can solve this?

TheReprator commented 10 months ago

One way is to create a dependency graph from there like we do with hilt or dagger, and remove the annotation from the class, it will work, bcz i had faced the issue, and was able to sort in this way, so i hope, it will get sorted, and this is a bug obviously

extmkv commented 10 months ago

@TheReprator can you provide an example?

TheReprator commented 10 months ago

I don't know, whether it helped or not, You can see this repo, for this use case,

Repository: https://github.com/TheReprator/AccountBook_Backend/tree/koinAnnotation Branch: koinAnnotation

More specifically, like this, https://github.com/TheReprator/AccountBook_Backend/blob/koinAnnotation/api/userIdentity/src/main/kotlin/dev/reprator/userIdentity/di/UserIdentityModule.kt

But you will not be able to run this, as it have a dependency which I need to provide dynamically, and I had raised a bug in koin for that,

Regards, Vikram Singh

arnaudgiuliani commented 9 months ago

sorry for the delay 🙏

@extmkv did you use includes to be sure you chain the modules?

C uses B uses A. Then you need to include A in B, and B in C.

ZackOPP commented 9 months ago

C uses B uses A. Then you need to include A in B, and B in C.

I have the same issue. Using include doesn't work for me, I still get the issue about the missing dependency.

extmkv commented 9 months ago

@arnaudgiuliani I don't think that will work at all. Did you had time to check the repository shared by @rodrirepresa ?

arnaudgiuliani commented 9 months ago

Ok, need to check more deeply 👍

extmkv commented 4 months ago

@arnaudgiuliani did you manage to have a look?

krzdabrowski commented 3 weeks ago

@arnaudgiuliani any updates on this? This issue still occurs on KA 1.4.0/2.0.0-Beta1 between two feature modules

BraveOwlet commented 3 weeks ago

@arnaudgiuliani Is there a way to fix it? I also have this problem on KA 1.4.0/2.0.0-Beta1