For Injecting Coroutines Dispatchers while we have Hilt or Dagger as DI framework, we can define annotations to differ between IO, Default and Main Dispatchers :
@Module
@InstallIn(SingletonComponent::class)
object DispatcherModule {
@IoDispatcher
@Provides
fun providesIoDispatcher(): CoroutineDispatcher = Dispatchers.IO
}
@Retention(AnnotationRetention.BINARY)
@Qualifier
annotation class IoDispatcher
How can we differ between IO, Default and Main Dispatchers when Using Koin? We can have following in Koin as far as I know :
val ioDispatcherModule = module {
single { Dispatchers.IO }
}