Hi everyone, I'm currently stuck in a "simple" use...
# dagger
t
Hi everyone, I'm currently stuck in a "simple" use case using Hilt: I want a Retrofit service singleton, which takes an OkHttpClient. The OkHttpClient has an interceptor, which uses the Retrofit service singleton (to make a certain request inside the interceptor) The problem is: -> The OkHttpClient takes a Retrofit as argument -> The Retrofit takes an OkHttpClient as argument Cheers
j
I think this is not a dagger problem, it is a design problem
OkHttp
shouldn't depend on retrofit
☝️ 1
t
I have solved it by creating a first Retrofit singleton, with the request needed in the interceptor
But there should be a way to implement it the other way around right?... If i wanted to get Retrofit object only when Interceptor handler is called...
Or maybe if i could setup the interceptor after creating the Retrofit instance...
a
From what I understood, that results in a circular dependency problem which is usually solved by injecting
dagger.Lazy<Retrofit>
in your Interceptor. But I'd advice you to change your design as @Javier pointed out, because using Lazy in Dagger is usually a code smell
👍 1
t
I've changed my design, and I'll definitely look into that, thanks 🎉
🎉 2