Skip to content

Instantly share code, notes, and snippets.

View itsandreramon's full-sized avatar

André Thiele itsandreramon

View GitHub Profile
plugins {
// ...
}
android {
// ...
}
dependencies {
// ...
[versions]
kotlin = "1.9.22"
agp = "8.2.0"
dagger = "2.50"
anvil = "2.4.8"
[plugins]
android-application = { id = "com.android.application", version.ref = "agp" }
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
kotlin-kapt = { id = "org.jetbrains.kotlin.kapt", version.ref = "kotlin" }
@SingleIn(AppScope::class)
class UserSessionManager @Inject constructor(private val app: App) {
private var _userCoroutineScope: UserCoroutineScope? = null
private val userCoroutineScope: CoroutineScope
get() = createUserCoroutineScope()
fun resetSession() {
_userCoroutineScope?.cancel()
class UserCoroutineScope(
private val parentScope: CoroutineScope
) : CoroutineScope by parentScope
@SingleIn(UserScope::class)
@MergeSubcomponent(UserScope::class)
interface UserComponent {
@Subcomponent.Factory
interface Factory {
fun create(
@BindsInstance userSession: UserSession,
@BindsInstance userCoroutineScope: UserCoroutineScope,
): UserComponent
@SingleIn(AppScope::class)
class UserSessionManager @Inject constructor(private val app: App) {
private var _userCoroutineScope: UserCoroutineScope? = null
private val userCoroutineScope: CoroutineScope
get() = createUserCoroutineScope()
fun resetSession() {
_userCoroutineScope?.cancel()
class App : Application() {
@Inject lateinit var userSessionManager: UserSessionManager
val appComponent: AppComponent by lazy {
DaggerAppComponent
.factory()
.create(this)
}
abstract class AppScope private constructor()
@SingleIn(AppScope::class)
@MergeComponent(AppScope::class)
interface AppComponent {
@Component.Factory
interface Factory {
fun create(
@BindsInstance app: App,
): AppComponent
}
class App : Application() {
val appComponent: AppComponent by lazy {
DaggerAppComponent
.factory()
.create(this)
}
}