It's to simplify Dagger's implementation, and to make it faster.
Why does Dagger not allow multiple qualifier annotations per element?
-
09-07-2023 - |
سؤال
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?
المحلول
نصائح أخرى
Please see this issue: JSR330 forbids to have have multiple qualifier annotations.
For more detail, this discussion might be helpful.
لا تنتمي إلى StackOverflow