koin-annotations icon indicating copy to clipboard operation
koin-annotations copied to clipboard

Compile check with multi module setup.

Open extmkv opened this issue 1 year ago • 10 comments

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.

extmkv avatar Nov 30 '23 18:11 extmkv

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

rodrirepresa avatar Dec 01 '23 12:12 rodrirepresa

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

extmkv avatar Jan 09 '24 08:01 extmkv

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

TheReprator avatar Jan 17 '24 19:01 TheReprator

@TheReprator can you provide an example?

extmkv avatar Jan 17 '24 21:01 extmkv

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

TheReprator avatar Jan 17 '24 22:01 TheReprator

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.

arnaudgiuliani avatar Jan 30 '24 10:01 arnaudgiuliani

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.

ZackOPP avatar Feb 06 '24 15:02 ZackOPP

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

extmkv avatar Feb 12 '24 21:02 extmkv

Ok, need to check more deeply 👍

arnaudgiuliani avatar Feb 15 '24 15:02 arnaudgiuliani

@arnaudgiuliani did you manage to have a look?

extmkv avatar Jul 19 '24 07:07 extmkv