# koin

Daniele Segato

03/29/2024, 3:37 PM
Learning Koin, how do I inject parameters in modules with koin-annotation? take this very basic example…
Copy code
class ApiModule

class Api(
    private val client: HttpClient,

// Application onCreate

startKoin {
    ApiModule().module, // how do I inject the httpClient?
how do I inject the http client in there?
the generated by ksp code
Copy code
public val com_example_api_ApiModule : Module = module {
	factory() { params -> com.example.api.Api(params.get()) } 
public val com.example.api.ApiModule.module : org.koin.core.module.Module get() = com_example_api_ApiModule
If it makes more sense…. Pretend this is the structure
Copy code
// HttpClientModule
class HttpClientFactory(@InjectedParam config: HttpClientConfig)

class HttpClientModule {

  fun httpClient(factory: HttpClientFactory): HttpClient = factory.create()

// ApiModule
class ApiImpl(@InjectedParam httpClient: HttpClient)

// RepositoryModule
class RepositoryImpl(@InjectedParam api: Api)

class MyActivity: AppCompatActivity() {
  val repository by inject<Repository>()
basically in this whole mess the only thing I would need to inject from outside is “HttpClientConfig” but how do I inject it? possibly only once

Alexandru Caraus

03/29/2024, 4:06 PM
Remove the injected param annotation
Take first example, add a function annotated with @Single which will create http client

Daniele Segato

03/29/2024, 5:09 PM
Thanks If i Do that I get an error from the ksp compiler (I’ve enabled
). If I disable that check it works - I think this is a bug