Few things you may consider updating in your application using dagger latest version

# Qualifiers for field attributes

When an annotation is placed on a property in Kotlin, it’s not clear whether Java will see that annotation on the field of the property or the method for that property. Setting the field: prefix on the annotation ensures that the qualifier ends up in the right place.

@Inject@field:Named("name")lateinit var someName: InterfaceName
@Inject@Named("name")lateinit var someName: InterfaceName

# @JvmStatic with @Provides functions optimization

Dagger’s generated code will be more performant if @Provides methods are static. To achieve this in Kotlin, We use a Kotlin object instead of a class and annotate our methods with @JvmStatic which we don’t need anymore from latest version.

@Moduleobject FeatureModule {@Provides
// No more @JvmStatic annotation
fun provideSomething() = SomeClass()}
// @Module is no longer needed here!
companion object {
// @JvmStatic is no longer needed here!
@Provides fun provideSomething() = SomeClass()
}

# @Component.Factory instead of @Component.Builder

Dagger introduced another amazing annotation named @Component.Factory to fix the problems were introduced as the result of using @Component.Builder. You can check this link for more details: https://android.jlelse.eu/dagger2-component-factory-and-subcomponent-factory-b181ec96b213

Future improvements coming…

@EntryPoint another interesting things still not added in this version (Will be reduced the pain to handle the AndroidInjection dependency in fragment and activity). Also probably @JvmSuppressWildcards will be removed from generics which may be available in next versions.

--

--

Senior Android Engineer @Delivery Hero | Android developer | Kotlin lover | Flutter explorer | Problem Solver

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Md Ali Hossain

Md Ali Hossain

Senior Android Engineer @Delivery Hero | Android developer | Kotlin lover | Flutter explorer | Problem Solver