-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Fix dispatcher qualifier target #2114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -18,8 +18,11 @@ package com.google.samples.apps.nowinandroid.core.common.network | |||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| import javax.inject.Qualifier | ||||||||||||||||||||||||||
| import kotlin.annotation.AnnotationRetention.RUNTIME | ||||||||||||||||||||||||||
| import kotlin.annotation.AnnotationTarget.FUNCTION | ||||||||||||||||||||||||||
| import kotlin.annotation.AnnotationTarget.VALUE_PARAMETER | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| @Qualifier | ||||||||||||||||||||||||||
| @Target(FUNCTION, VALUE_PARAMETER) | ||||||||||||||||||||||||||
|
Comment on lines
+21
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To support field injection (common in Android components like Activities and Fragments) and to ensure compatibility with various Kotlin property usage patterns, it is recommended to include
Suggested change
|
||||||||||||||||||||||||||
| @Retention(RUNTIME) | ||||||||||||||||||||||||||
| annotation class Dispatcher(val niaDispatcher: NiaDispatchers) | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When explicitly defining annotation targets for a Dagger qualifier in Kotlin, it is important to include
FIELDandPROPERTYin addition toFUNCTIONandVALUE_PARAMETER. This ensures that the qualifier can be used for field injection (e.g., in Activities or Fragments usinglateinit var), which is a common pattern in Android development. Restricting it to onlyFUNCTIONandVALUE_PARAMETERmight break existing or future field injections.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestion. I kept the target list scoped to the current usages in this project and to #2001.
@Dispatcheris currently used on Hilt provider functions and injected value parameters, so this PR includesFUNCTIONandVALUE_PARAMETER. I left outFIELDandPROPERTYbecause there are no current field/property injection usages for this qualifier, and adding them would broaden the allowed targets beyond the issue's requested restriction.