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

Missing support for multibinds #250

Open
kaserdan opened this issue May 16, 2023 · 3 comments
Open

Missing support for multibinds #250

kaserdan opened this issue May 16, 2023 · 3 comments

Comments

@kaserdan
Copy link

Dagger allows you to bind several objects into a collection even when the objects are bound in different modules using multibindings. Similar thing is possible with Koin. Is there any way to binds object into collection in Koject?

@mori-atsushi
Copy link
Owner

There is not multibinds feature in Koject.

I have never used that feature, so I do not know why it is necessary.
If you tell me the use case you imagine, I will consider it.

@kaserdan
Copy link
Author

kaserdan commented May 17, 2023

We have multi module project (with multiple apps) where some modules expose ktor interceptor. Then some other module can "collect" these interceptors without having dependecy on them, so networking module can get these interceptor from "top" - base on application being build.

@mori-atsushi
Copy link
Owner

I'm not sure about ktor, but I think it works like this:

// common module
@Qualifier
@Retention(AnnotationRetention.BINARY)
annotation class Interceptor1

@Qualifier
@Retention(AnnotationRetention.BINARY)
annotation class Interceptor2
// lib module1
@Provides
@Interceptor1
fun provideInterceptor1(): Interceptor {
    /* ... */
}
// lib module2
@Provides
@Interceptor2
fun provideInterceptor2(): Interceptor {
    /* ... */
}
// app module
@Provides
fun provideInterceptorSet(
    @Interceptor1
    interceptor1: Interceptor,
    @Interceptor2
    interceptor2: Interceptor
): Set<Interceptor> {
    return setOf(interceptor1, interceptor2)
}
// networking module
@Provides
class SameClass(
    private val providerSet: Set<Provider>
) {
    /* ... */
}

If there is a IntoSet annotation like dagger, we can remove the provider code in the app module.
But it may be hard to know what will be used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants