question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@Qualifier causes: [Dagger/MissingBinding] @JvmStatic solves ONLY constructor injection

See original GitHub issue

I’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:closed
  • Created 4 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
tbroyercommented, Sep 4, 2019

How about @field:CalendarPickerDateFormat? https://github.com/google/dagger/issues/900#issuecomment-337038961

1reaction
tbroyercommented, Sep 5, 2019
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found