Skip to content Skip to sidebar Skip to footer

The Annotation For Provider Function Of Dagger Module Class

I am developing an Android project with Kotlin and Dagger 2. I have a NetworkModule in which I define some provider functions. @Module object NetworkModule { @Provides @JvmSt

Solution 1:

If you declare your module as a Kotlin object, @JvmStatic was required. That limitation was removed with dagger 2.25 You can also check this issue for more info.

If you use Dagger 2.25 or newer there is no reason to use @JvmStatic anymore.

From the @Reusable docs:

A scope that indicates that the object returned by a binding may be (but might not be) reused.

{@code @Reusable} is useful when you want to limit the number of provisions of a type, but there is no specific lifetime over which there must be only one instance.

If you inject the same thing in multiple places, and having the same instance is not a problem, this can help not to create a new object for each usage.

@JvmStatic and @Reusable are not related to each other, depending on your need you can use one, the other or both of them.

Post a Comment for "The Annotation For Provider Function Of Dagger Module Class"