Your Interceptor will need to introduce itself into the Interceptor#intercept() method. This way your Retrofit service (including the OkHttpClient dependency with an added sniffer) can be satisfied without a dependency loop.
My NetworkComponent (which provides my Retrofit service) lives in my Application class. The following is an example of entering it using the Context application.
public class AuthInterceptor implements Interceptor { @Inject RestService restService; public AuthInterceptor(Context context) { mContext = context; } @Override public Response intercept(Chain chain) throws IOException {
You can also just set a local variable without entering the whole class, perhaps getting better performance.
RestService restService = InjectHelper.getNetworkComponent(mContext).restService();
source share