Issue with Multibindings
See original GitHub issueI am using Anvil + dagger multibindings to build a plugin system and I’ve encountered the following issue.
Consider the following setup (omitting the AppComponent for brevity)
interface PluginPoint<T> {
fun getPlugins(): List<T>
}
interface PrinterPlugin {
fun print()
}
@Module
@ContributesTo(AppScope::class)
class ExamplePluginsModule {
@Provides
@IntoSet
fun provideFoo(): PrinterPlugin = Foo()
@Provides
@IntoSet
fun provideBar(): PrinterPlugin = Bar()
}
class PrinterPluginPoint @Inject constructor(
private val plugins: Set<PrinterPlugin>
): PluginPoint<PrinterPlugin> {
override fun getPlugins(): List<PrinterPlugin> {
return plugins.toList()
}
}
class Foo: PrinterPlugin {
override fun print() {
Timber.d("Foo")
}
}
class Bar: PrinterPlugin {
override fun print() {
Timber.d("Bar")
}
}
Then in the Application class
open class App : HasAndroidInjector, Application() {
//...
@Inject
lateinit var printerPluginPoint: PrinterPluginPoint
override fun onCreate() {
super.onCreate()
// HERE configure DI...
printerPluginPoint.getPlugins().forEach { it.print() }
}
//...
}
Result: [Dagger/MissingBinding] java.util.Set<? extends io.avs.android.plugins.PrinterPlugin>
However, replacing the dependency of PrinterPluginPoint to a Lazy<Set<PrinterPlugin>> fixes the issue. I guess the codegen path is different
Is this known? or maybe I am missing something?
Issue Analytics
- State:
- Created 3 years ago
- Comments:5
Top Results From Across the Web
How to fix "Unable to load class 'dagger.Multibindings'" due to ...
1 Answer 1 · Ok never mind the problem still persists. · Invalidate cache and restart your porject and rebuild it. · If...
Read more >Using Dagger 2 Multibindings to Avoid Coupling in a Multi ...
The problem gets even worse when you don't want to couple app flavors to features they don't use. In this article I'll show...
Read more >IntoSet: Dagger Multibindings and Architecture - Adam Bennett
Multibindings is one of them, which is a shame because it's a highly useful pattern which can solve real problems.
Read more >Re: Issue 369 in google-guice: Convenient way to expose ...
Comment #3 on issue 369 by Industri...@gmail.com: Convenient way to expose multibindings and mapbindings from PrivateModules
Read more >MultiBindings - XAML vs code-behind - Microsoft Q&A
I copy the code from this link, but I am still cannot reproduce this issue, my xamarin.forms version is 5.0.2196. Could you share...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

There’s a bug in your code, it’s unrelated to Anvil. Change the class to this and it works:
Sorry for the late response, thanks a lot! Our of curiosity, do you happen to know why
Lazyovercomes the issue with wildcards, without needing the annotation to suppress its generation?