Domanda

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?

È stato utile?

Soluzione

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

Altri suggerimenti

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

For more detail, this discussion might be helpful.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top