tezvyn:

How do you inject two different OkHttpClient instances with Hilt?

Source: developer.android.comintermediate

Tests Hilt qualifiers for same-type bindings. Answer: define a custom @Qualifier (or @Named), annotate two @Provides methods and the injection site. Red flag: manual client creation or subclassing OkHttpClient instead of qualifying the binding.

Tests whether you understand Hilt qualifiers for distinguishing multiple bindings of the same type. A strong answer: first, define a custom @Qualifier annotation (preferred over @Named for type safety); second, create two @Provides methods in a Hilt module, each returning a configured OkHttpClient and annotated with the respective qualifier; third, annotate the constructor or field at the injection site with the matching qualifier.

Read the original → developer.android.com

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.

How do you inject two different OkHttpClient instances with Hilt? · Tezvyn