I was reading the data layer guide by Google and in the linked segment, they have the following snippet:
class NewsRemoteDataSource(
private val newsApi: NewsApi,
private val ioDispatcher: CoroutineDispatcher
) {
/**
* Fetches the latest news from the network and returns the result.
* This executes on an IO-optimized thread pool, the function is main-safe.
*/
suspend fun fetchLatestNews(): List<ArticleHeadline> =
// Move the execution to an IO-optimized thread since the ApiService
// doesn't support coroutines and makes synchronous requests.
withContext(ioDispatcher) {
newsApi.fetchLatestNews()
}
}
}
// Makes news-related network synchronous requests.
interface NewsApi {
fun fetchLatestNews(): List<ArticleHeadline>
}
Injecting the NewsApi dependency using Koin is pretty straightforward, but how can I inject a CoroutineDispatcher instance using Koin? I used the search functionality on Koin's website but nothing came up. A filtered ddg search doesn't yield many results either.