title: Is Dynamic Dependency Injection with Koin possible
body: <p>I am investigating <code>Koin</code> dependency injection library in my current <code>Android</code> application.</p>
  
  <p>I have a <code>CoroutineWorker</code> that completes all my background work.</p>
  
  <p>What I would like to do is Dynamically inject a lambda for each type of background work I have.</p>
  
  <p>I have the following code that works, however it is not Dynamic</p>
  
  <p>Koin Module:</p>
  
  <pre><code>const val BackgroundLambdaName: String = "back-ground-lambda"
  
  val lambdaModule = module {
  
      single(qualifier = named(BackgroundLambdaName)) {
          background
      }
  }
  
  private val background: suspend CoroutineScope.(Service) -&gt; Unit = { service: Service -&gt;
      val limit: Int = 200
      var offset: Int = 0
  
      loop@ while (true) {
  
          val networkResponse = service.move(options = mutableMapOf("limit" to limit, "offset" to offset))
  
          if (networkResponse.next == null) {
              break@loop
          }
          offset += limit
      }
  }
  </code></pre>
  
  <p>And my <code>CoroutineWorker</code>:</p>
  
  <pre><code>class BackgroundWorker(context: Context, params: WorkerParameters) : CoroutineWorker(context, params), KoinComponent {
  
      private val service: Service by inject()
      private val x_background: suspend CoroutineScope.(Service) -&gt; Unit by inject(qualifier = named(BackgroundLambdaName))
  
      override suspend fun doWork(): Result = coroutineScope {
  
          withContext(Dispatchers.IO) {
              downloadSynchronously(this)
              Result.success()
          }
      }
  
      private suspend fun downloadSynchronously(coroutineScope: CoroutineScope) {
          x_background(coroutineScope, service)
      }
  }
  </code></pre>
  
  <p>Is there any approach I can take that will allow me to specify different lambdas at runtime to inject into my <code>CoroutineWorker</code>?</p>
  
  <p>For example if my lambda Koin module had 10 lambdas defined</p>
  
  <pre><code>BackgroundLambdaName_0 - BackgroundLambdaName_9
  </code></pre>
  
  <p>Then when starting my unique background work as follows:</p>
  
  <pre><code>val constraints = Constraints.Builder()
      .setRequiredNetworkType(NetworkType.CONNECTED)
      .setRequiresBatteryNotLow(true)
      .setRequiresCharging(true)
      .build()
  
  val backgroundWorkRequest = OneTimeWorkRequestBuilder&lt;BackgroundWorker&gt;()
      .setConstraints(constraints)
      .setBackoffCriteria(
          BackoffPolicy.EXPONENTIAL,
          OneTimeWorkRequest.MIN_BACKOFF_MILLIS,
          TimeUnit.MILLISECONDS
      ).build()
  
  // DYNAMICALLY set qualifier = named(BackgroundLambdaName) to one of 
  // BackgroundLambdaName_0 - BackgroundLambdaName_9
  
  WorkManager.getInstance(application).enqueueUniqueWork(UNIQUE_WORK_NAME, ExistingWorkPolicy.KEEP, backgroundWorkRequest)
  </code></pre>