Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Dagger not allow multiple qualifier annotations per element?

Tags:

dagger

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?

like image 240
f2prateek Avatar asked Oct 30 '25 17:10

f2prateek


2 Answers

It's to simplify Dagger's implementation, and to make it faster.

like image 196
Jesse Wilson Avatar answered Nov 02 '25 07:11

Jesse Wilson


Please see this issue: JSR330 forbids to have have multiple qualifier annotations.

For more detail, this discussion might be helpful.

like image 37
John-Paul Cunliffe Avatar answered Nov 02 '25 07:11

John-Paul Cunliffe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!