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.

Combine @BindsInstance & @IntoSet

See original GitHub issue

I have some custom initialization code to be run at a well-defined time. The code is passed to a Component from the outside via @BindsInstance. I’d like to do the following:

@BindsInstance Builder foo(@IntoSet Runnable initCode);

This does not compile due to @IntoSet. @ElementsIntoSet has the same issue. Would it be possible to support this pattern?

There are other Runnable pieces of initialization code within the Component that are in this same set, but I also need to pass in this one piece of external code.

Right now I pass the code in via another binding, and use a separate @Provides @IntoSet method in a module to funnel it into the set. Would be nice to do it directly.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:2
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
ronshapirocommented, Mar 25, 2018

I don’t see a compelling reason not to allow this. This seems reasonable to me. I can look into what it would look like to add support for this but I imagine it wouldn’t be so hard.

1reaction
cgdeckercommented, Mar 20, 2019

I think as a workaround you’d just define a module that has an instance @Provides @ElementsIntoSet method that returns the set of values you want contributed to the set, and provide your own way of building an instance of that module such that it returns the set of elements you want. Then you’d create an instance of the module and set it when creating the component.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Multibindings - Dagger
Dagger allows you to bind several objects into a collection even when the objects are bound in different modules using multibindings. Dagger assembles...
Read more >
IntoSet: Dagger Multibindings and Architecture - Adam Bennett
Set Multibindings are a fantastically useful tool in multi-module projects where you might want a Gradle module to register some specific type ...
Read more >
Modular architecture- Using Dagger Multibinding to initialize ...
Through this post, we'll explore how we can use Dagger multibindings to make this easier. If you aren't familiar with Multibindings and @IntoSet...
Read more >
Dagger 2 for Android, Part VI ー @Component.Builder and ...
In this post, let's look at how it can be done using @Component.Builder and @BindsInstance . Photo by shiangling from Unsplash. Dagger 2...
Read more >
Dagger 2 Subcomponent or Subcomponent Builder? - Medium
@BindsInstance fun data(data: Data): Builder fun build(): ChildComponent } }. Shown above, we can bind the data instance to ChildModule through the Builder....
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