Created
January 22, 2022 04:51
-
-
Save ravisorathiya/1c9be72a01a68f2d90c489d4f58cdd5a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.app.Application | |
import android.content.Context | |
import dagger.Module | |
import dagger.Provides | |
import dagger.hilt.InstallIn | |
import dagger.hilt.components.SingletonComponent | |
import kotlinx.coroutines.CoroutineDispatcher | |
import kotlinx.coroutines.Dispatchers | |
import kotlinx.coroutines.MainCoroutineDispatcher | |
import javax.inject.Qualifier | |
import javax.inject.Singleton | |
@Module | |
@InstallIn(SingletonComponent::class) | |
object DispatcherModule { | |
@Singleton | |
@Provides | |
fun provideContext(application: Application): Context = application.applicationContext | |
@MainDispatcher | |
@Provides | |
@Singleton | |
fun provideMainDispatcher(): MainCoroutineDispatcher = Dispatchers.Main | |
@DefaultDispatcher | |
@Provides | |
@Singleton | |
fun provideDefaultDispatcher(): CoroutineDispatcher = Dispatchers.Default | |
@IoDispatcher | |
@Provides | |
@Singleton | |
fun provideIODispatcher(): CoroutineDispatcher = Dispatchers.IO | |
@UnconfinedDispatcher | |
@Provides | |
@Singleton | |
fun provideUnconfinedDispatcher(): CoroutineDispatcher = Dispatchers.Unconfined | |
} | |
@Qualifier | |
@Retention(AnnotationRetention.BINARY) | |
annotation class IoDispatcher | |
@Qualifier | |
@Retention(AnnotationRetention.BINARY) | |
annotation class MainDispatcher | |
@Qualifier | |
@Retention(AnnotationRetention.BINARY) | |
annotation class DefaultDispatcher | |
@Qualifier | |
@Retention(AnnotationRetention.BINARY) | |
annotation class UnconfinedDispatcher |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment