title: How pass to module of Dagger parameter action: (() -> Unit) for repeat request after lost connection
body: <p>I want check internet connection use ConnectivityInterceptor and passed parameter <code>action: (() -&gt; Unit)</code> to module of dagger(NetworkModule) for repeat call request after connection was lost, how can I do it?</p>
  
  <pre><code>@Module
  class NetworkModule {
  
      private fun getOkHttpClient(context: Context, action: (() -&gt; Unit)): OkHttpClient {
          return OkHttpClient.Builder()
                  .hostnameVerifier { s, sslSession -&gt; true }
                  .connectTimeout(TIME.toLong(), TimeUnit.SECONDS)
                  .readTimeout(TIME.toLong(), TimeUnit.SECONDS)
                  .writeTimeout(TIME.toLong(), TimeUnit.SECONDS)
                  .addInterceptor(HttpLoggingInterceptor().setLevel(if (BuildConfig.DEBUG) HttpLoggingInterceptor.Level.BODY else HttpLoggingInterceptor.Level.NONE))
                  .addInterceptor(ConnectivityInterceptor(context, action))
                  .addInterceptor { chain -&gt;
                      val original = chain.request()
                      val requestBuilder = original.newBuilder()
  
                      val token = BEARER + UserStorage.getInstance().token
                      val uuid = UserStorage.getInstance().uuid
  
                      val userAgent = Build.MANUFACTURER + " / " + Build.MODEL + " / " + Build.VERSION.RELEASE + " / " + VERSION_NAME + " / Android"
  
                      if (!TextUtils.isEmpty(UserStorage.getInstance().token)) {
                          requestBuilder.header(AUTHORIZATION, token)
                      }
                      if (!TextUtils.isEmpty(UserStorage.getInstance().uuid)) {
                          requestBuilder.header(X_UUID, UserStorage.getInstance().uuid)
                      }
                      requestBuilder.header(USER_AGENT, userAgent)
                      requestBuilder
                              .header("Accept", "application/json")
                              .method(original.method(), original.body())
                      chain.proceed(requestBuilder.build())
                  }
                  .retryOnConnectionFailure(true)
                  .build()
      }
  
      @Provides
      @Singleton
      fun provideRetrofit(gson: Gson, context: Context, action: (() -&gt; Unit)): Retrofit {
          return Retrofit.Builder()
                  .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                  .addConverterFactory(ScalarsConverterFactory.create()) // this line cut quotes
                  .addConverterFactory(GsonConverterFactory.create(gson))
                  .client(getOkHttpClient(context, action))
                  .baseUrl(BASE_URL)
                  .build()
      } ...
  </code></pre>
  
  <p>my ConnectivityInterceptor :</p>
  
  <pre><code>class ConnectivityInterceptor(private val context: Context, private val action: (() -&gt; Unit)): Interceptor {
  
      @Throws(IOException::class)
      override fun intercept(chain: Interceptor.Chain): Response {
          if (!isNetworkAvailable(context)) {
              showErrorScreen(context, action, ERROR_CLIENT)
          }
          val builder = chain.request().newBuilder()
          return chain.proceed(builder.build())
      }
  
  }
  </code></pre>
  
  <p>my AppModule :</p>
  
  <pre><code>@Module
  class AppModule(private val app: App) {
  
      @Provides
      @Singleton
      fun provideContext(): Context = app
  
      @Provides
      fun provideApplication(): Application = app
  
      @Provides
      @Singleton
      fun providesGson(): Gson =
              GsonBuilder()
                      .serializeNulls()
                      .setLenient()
                      .registerTypeAdapterFactory(ArrayAdapterFactory())
                      .setDateFormat("yyyy-MM-dd HH:mm:ss")
                      .create()
  
  }
  </code></pre>
  
  <p>my service :</p>
  
  <pre><code>interface ApiService {
  
      @GET(VERSION)
      fun getVersion(): Observable&lt;VersionResponse&gt;
  
      @GET(DICTIONARIES)
      fun getDictionaries(): Observable&lt;JsonObject&gt;
  ...
  </code></pre>
  
  <p>also </p>
  
  <pre><code>class NetworkManager @Inject constructor(private val api: ApiVideo) {
  
      fun getVersion(): Observable&lt;VersionResponse&gt; {
          return api.getVersion()
      }
  
      fun getDictionaries(): Observable&lt;JsonObject&gt; {
          return api.getDictionaries()
      } ...
  </code></pre>
  
  <p>and for example - my presenter : </p>
  
  <pre><code>class SplashPresenter @Inject constructor(): SplashContract.Presenter {
  
      @Inject
      lateinit var apiManager: NetworkManager
      private var compositeDisposable = CompositeDisposable()
      var view: SplashContract.View? = null
  
      override fun detachView(view: SplashContract.View) {
          this.view = null
      }
  
      override fun attachView(view: SplashContract.View) {
          this.view = view
      }
  
      override fun destroy() {
          compositeDisposable.clear()
      }
  
      override fun getDictionaries(context: Context) {
          view?.let {
              apiManager.getDictionaries()
                      .observeOn(AndroidSchedulers.mainThread())
                      .subscribeOn(Schedulers.io())
                      .subscribe({ result -&gt;
                          LocalizationData.getInstance(context).saveData(result)
                          view?.showOrHideProgressBar(false)
                          view?.goNextScreen()
                      }, { error -&gt;
                          handleAnyError(view!!, error, context) { getDictionaries(context) }
                      }).addToCompositeDisposable(compositeDisposable)
          }
      }
  
      override fun getVersion(context: Context) {
          view?.let {
                  apiManager.getVersion()
                          .observeOn(AndroidSchedulers.mainThread())
                          .subscribeOn(Schedulers.io())
                          .subscribe({ result -&gt;
                              view?.showOrHideProgressBar(false)
                              view?.showResultVersion(result)
                          }, { error -&gt;
                              handleAnyError(view!!, error, context) { getVersion(context) }
                          }).addToCompositeDisposable(compositeDisposable)
          }
      }
  
  }
  </code></pre>