[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:
- Created 4 years ago
- Reactions:1
- Comments:5 (1 by maintainers)
Top 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 >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 FreeTop 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
Top GitHub Comments
When interfaces
A
andB
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 bloatsCombined
interface with unrelated methods.For example, we are using a hierarchy of
@Component
s. Each@Component
declares its ownDependencies
which user should fulfill to instantiate that component. And in the case when one@Component A
should be instantiated inside another@Component B
component’sB
dependencies could extend the component’sA
dependencies.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.