Skip to content

Instantly share code, notes, and snippets.

@Rasalexman
Created May 13, 2020 18:59
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 Rasalexman/cb45bf27d2ddee7eefe8a490e5218118 to your computer and use it in GitHub Desktop.
Save Rasalexman/cb45bf27d2ddee7eefe8a490e5218118 to your computer and use it in GitHub Desktop.
@BindSingle(
toClass = OkHttpClient::class,
toModule = "OkHttpModule"
)
fun createOkHttpClient(cache: Cache? = null): OkHttpClient {
val httpClient = OkHttpClient.Builder()
httpClient.connectTimeout(60, TimeUnit.SECONDS)
httpClient.writeTimeout(60, TimeUnit.SECONDS)
httpClient.readTimeout(60, TimeUnit.SECONDS)
// cache
cache?.let {
httpClient.cache(it)
}
return httpClient.build()
}
// It will generate module with single binding
import com.pathtofile.createOkHttpClient
val providersModule: IKodiModule = kodiModule {
bind<OkHttpClient>() with provider {
createOkHttpClient(
cache = instance<Cache>()
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment