Created
May 13, 2020 18:59
-
-
Save Rasalexman/cb45bf27d2ddee7eefe8a490e5218118 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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