@Qualifier causes: [Dagger/MissingBinding] @JvmStatic solves ONLY constructor injection
See original GitHub issueI’m having this issue:
ApplicationComponent.java:8: error: [Dagger/MissingBinding] @… java.text.SimpleDateFormat cannot be provided without an @Provides-annotated method.
Module
@Module
abstract class ApplicationModule {
@Binds
@AppContext
abstract fun application(app: App): Context
@Module
companion object {
...
@Provides
@Singleton
@CalendarPickerDateFormat
fun provideCalendarPickerDateFormat(): SimpleDateFormat {
return SimpleDateFormat("dd/MMM/yyyy", Locale.getDefault())
}
}
}
Qualifier
@Qualifier
@Retention(AnnotationRetention.RUNTIME)
annotation class CalendarPickerDateFormat
Class
@ActivityScope
class MyClass
@Inject constructor(
...,
@CalendarPickerDateFormat private val calendarDateFormat: SimpleDateFormat
) {...}
Even if I add @Target(AnnotationTarget.VALUE_PARAMETER, AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY)
to the Qualifier and change the class constructor to @param:CalendarPickerDateFormat
, I get the same error.
What’s missing?
Possible solution
Adding @JvmStatic
like:
@Provides
@Singleton
@JvmStatic
@CalendarPickerDateFormat
fun provideCalendarPickerDateFormat(): SimpleDateFormat {
return SimpleDateFormat("dd/MMM/yyyy", Locale.getDefault())
}
Solves constructor injection but not field injection:
@Inject
@CalendarPickerDateFormat lateinit var date : SimpleDateFormat
Why?
NOTE: I’ve tried also the @Module object class
approach but I have the same outcome.
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (2 by maintainers)
Top Results From Across the Web
Qualifier causes: [Dagger/MissingBinding] when field injecting
Solves constructor injection but not field injection: @Inject @CalendarPickerDateFormat lateinit var date : SimpleDateFormat.
Read more >Dependency injection and programmatic lookup
First, the container calls the bean constructor (the default constructor or the one annotated @Inject ), to obtain an instance of the bean....
Read more >Circular Dependencies in Spring - Baeldung
A circular dependency occurs when a bean A depends on another bean B, ... It can happen in Spring when using constructor injection....
Read more >Dependency injection with Hilt | Android Developers
Hilt only creates a scoped binding once per instance of the component that the binding is scoped to, and all requests for that...
Read more >Contexts and Dependency Injection - Quarkus
Most of the existing CDI code should work just fine but there are some small differences which follow from the Quarkus architecture and...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
How about
@field:CalendarPickerDateFormat
? https://github.com/google/dagger/issues/900#issuecomment-337038961This should be fixed by https://github.com/google/dagger/commit/42a3a7b9a652b115feb4a8bbf9edbb9919707a81 IIUC