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.

[Dagger/DuplicateBindings] if component's dependencies extends two or more interfaces with same method

See original GitHub issue
@Component(dependencies = Comp.Combined.class)
interface Comp {
    interface A {
        String s();
    }
    interface B {
        String s();
    }

    interface Combined extends A, B {
//        uncomment to make it compile
//        @Override
//        String s();
    }

    String s();
}

Error:

[Dagger/DuplicateBindings] java.lang.String is bound multiple times:
interface Comp {
^
      String com.example.playground.Comp.A.s()
      String com.example.playground.Comp.B.s()
      java.lang.String is provided at
          com.example.playground.Comp.s()

Looks like this issue is related to https://github.com/google/dagger/pull/472

Is it the intended behavior? At first glance, it looks like dagger shouldn’t treat methods inherited from different interfaces as duplicate bindings if they have the same signature and qualifiers.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
Tagakovcommented, Sep 24, 2019

When interfaces A and B are quite big and you have to extend both it becomes hard to identify the intersection between them, also overridden methods doesn’t bring any new information to the reader and bloats Combined interface with unrelated methods.

For example, we are using a hierarchy of @Components. Each @Component declares its own Dependencies which user should fulfill to instantiate that component. And in the case when one @Component A should be instantiated inside another @Component B component’s B dependencies could extend the component’s A dependencies.

@Component(dependencies = A.Dependencies.class)
interface A {
  interface Dependencies {
    //...
  }
}

@Component(dependencies = B.Dependencies.class)
interface B {
  interface Dependencies extends A.Dependencies, C.Dependencies, Etc.Dependencies {
    //...
  }
}
0reactions
Chang-Ericcommented, Jan 25, 2020

Going to work on fixing this, though FWIW this is still going to be somewhat fragile for you since it depends on naming of the methods. So if those two interfaces that presumably live apart name the getters differently, things will break and there won’t really be a good answer to fixing it besides making the names match or factoring out shared deps into a single interface.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dagger 2 - two provides method that provide same interface
I recently post the answer to a question like this in this post : Dagger 2 : error while getting a multiple instances...
Read more >
Two interfaces with same methods having same signature but ...
If two interfaces contain a method with the same signature but different return types, then it is impossible to implement both the interface...
Read more >
Guide to Inheritance in Java - Baeldung
In the same way, interfaces can extend existing interfaces. We'll notice the use of multiple terms to refer to a type which is...
Read more >
How to register a service with multiple interfaces in ASP.NET ...
In this post I describe how to register a concrete class with multiple public interfaces in the Microsoft.Extensions.
Read more >
Using Dagger in multi-module apps - Android Developers
Implementation with Dagger subcomponents; Component dependencies with ... a Dagger module with @Provides or @Binds methods if construction ...
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