Skip to content

Instantly share code, notes, and snippets.

@theanilpaudel
Created June 15, 2022 14:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theanilpaudel/8c4cba9edb8ecb14c33dec4e00e33ee4 to your computer and use it in GitHub Desktop.
Save theanilpaudel/8c4cba9edb8ecb14c33dec4e00e33ee4 to your computer and use it in GitHub Desktop.
DaggerHilt implementation of Dependency Injection of Network module.
@Provides
@Singleton
fun provideTokenInterceptor():TokenInterceptor {
return TokenInterceptor()
}
@Provides
@Singleton
fun provideTokenAuthenticator(@ApplicationContext context: Context):TokenAutheticator {
return TokenAutheticator(context)
}
@Provides
@Singleton
fun provideOkhttp(tokenInterceptor: TokenInterceptor,tokenAutheticator: TokenAutheticator): OkHttpClient {
val logging = HttpLoggingInterceptor()
logging.setLevel(HttpLoggingInterceptor.Level.BODY)
val client = OkHttpClient.Builder()
.addInterceptor(logging)
.addInterceptor(tokenInterceptor)
.authenticator(tokenAutheticator)
.build()
return client
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment