Say I have two services AService and BService, both of which require an api key.
So in my modules, I can't do something like:
@Provides @Singleton @A @ApiKey String provideAKey() { return "a"; }
@Provides @Singleton @B @ApiKey String provideBKey() { return "b"; }
(Dagger would complain with "Only one qualifier annotation is allowed per element").
Instead what I have to do, is define two separate qualifiers for each combination: @ApiKeyA and @ApiKeyB.
For a service with multiple dependencies, (think network client, request headers, etc.) it gets cumbersome to define these qualifiers for each combination, rather than simply combine different annotations.
Is there a reason why this explicitly disallowed?
It's to simplify Dagger's implementation, and to make it faster.
Please see this issue: JSR330 forbids to have have multiple qualifier annotations.
For more detail, this discussion might be helpful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With