question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issue with Multibindings

See original GitHub issue

I 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:closed
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
vRallevcommented, Aug 16, 2020

There’s a bug in your code, it’s unrelated to Anvil. Change the class to this and it works:

class PrinterPluginPoint @Inject constructor(
  private val plugins: Set<@JvmSuppressWildcards PrinterPlugin>
): PluginPoint<PrinterPlugin> {
  override fun getPlugins(): List<PrinterPlugin> {
    return plugins.toList()
  }
}
0reactions
aitorvscommented, Aug 28, 2020

Sorry for the late response, thanks a lot! Our of curiosity, do you happen to know why Lazy overcomes the issue with wildcards, without needing the annotation to suppress its generation?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found