Daniele Segato
03/29/2024, 3:37 PM@Module()
@ComponentScan("com.example.api")
class ApiModule
@Factory
class Api(
@InjectedParam
private val client: HttpClient,
)
// Application onCreate
startKoin {
modules(
ApiModule().module, // how do I inject the httpClient?
)
}
how do I inject the http client in there?Daniele Segato
03/29/2024, 3:42 PMpublic 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
Daniele Segato
03/29/2024, 3:56 PM// HttpClientModule
@Factory
class HttpClientFactory(@InjectedParam config: HttpClientConfig)
@Module
class HttpClientModule {
@Single
fun httpClient(factory: HttpClientFactory): HttpClient = factory.create()
}
// ApiModule
@Factory
class ApiImpl(@InjectedParam httpClient: HttpClient)
// RepositoryModule
@Single
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 onceAlexandru Caraus
03/29/2024, 4:06 PMAlexandru Caraus
03/29/2024, 4:08 PMDaniele Segato
03/29/2024, 5:09 PMKOIN_CONFIG_CHECK
).
If I disable that check it works - I think this is a bugDaniele Segato
03/29/2024, 5:16 PM