Skip to content

Instantly share code, notes, and snippets.

@sphrak
Created June 16, 2023 08:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sphrak/1b1d1f1c0f7d9260a6f1434a77476218 to your computer and use it in GitHub Desktop.
Save sphrak/1b1d1f1c0f7d9260a6f1434a77476218 to your computer and use it in GitHub Desktop.
dagger2 desktop jvm
@DeviceScope
@Component(
modules = [
DeviceModule::class
],
dependencies = [
// shared dependencies
AppComponent::class
]
)
interface DeviceComponent {
fun provideViewModel(): DeviceViewModel
@Component.Factory
interface Factory {
fun create(
appComponent: AppComponent
): DeviceComponent
}
}
@Module
object DeviceModule {
@Provides
fun provideCoroutineDispatcher(): CoroutineDispatcher = Dispatchers.IO
@Provides
fun provideCoroutineScope(
coroutineDispatcher: CoroutineDispatcher
): CoroutineScope = CoroutineScope(Job() + coroutineDispatcher)
}
@Scope
@Retention
annotation class DeviceScope
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment