我收到了这个错误.我正在使用KOIN进行依赖项注入. 当UserInfoContainer作用域处于活动状态时,我希望我的约会存储库处于活动状态. 找不到class:‘com.flow.domain.repository.AppointmentsRepository’.的定义判断你的定义!

UserInfoContainer类

class UserInfoContainer(private val encryptedLocalDatabase: EncryptedLocalDatabase) :
    KoinScopeComponent {
    override val scope: Scope get() = getOrCreateScope().value
var user: User?
    get() = encryptedLocalDatabase.user
    set(it) {
        if (it != encryptedLocalDatabase.user) {
            encryptedLocalDatabase.user = it
            scope.close()
        }
        }
}

帖子主题:重新归档

single { UserInfoContainer(encryptedLocalDatabase = get()) }

    scope<UserInfoContainer> {
        scoped<AppointmentsRepository> {
            AppointmentsRepositoryImplementation(
                apiService = get(),
                clinicId = get<UserInfoContainer>().user.let { it!!.clinicId }
            )
        }
    }

约会UseCase类

class AppointmentsUseCase : KoinComponent {
    private val appointmentsRepository: AppointmentsRepository by inject()

    suspend fun getAppointments(startDate: LocalDateTime, endDate: LocalDateTime): List<Appointment> =
        appointmentsRepository.getAppointments(startDate, endDate)
}

推荐答案

这就是我应该如何在UseCase中注入依赖项

class AppointmentsUseCase : KoinComponent {
    private val userInfoContainer: UserInfoContainer by inject()
    private val appointmentsRepository: AppointmentsRepository = userInfoContainer.scope.get()

    suspend fun getAppointments(
        startDate: LocalDateTime,
        endDate: LocalDateTime
    ): List<Appointment> =
        appointmentsRepository.getAppointments(startDate, endDate)
}

Android相关问答推荐

如何在Android中使用TextView设置动态文本的样式

将Android Studio插件复制到离线网络

如何制作带有图标和文本的Fab

推断的类型是片段,但应为上下文

Android App Google AdMob";广告加载失败:3;带有测试ID,&q;广告加载失败:1 for My Gahad

我怎样才能画一条线在喷气背包组成和有一个自定义的角落?

如何在DownloadManager Android中显示ProgressBar和Complete Listener

如何在android库中关联应用程序链接?

在c中更新MVVMCross中TextView的Alpha#

可组合函数无限地从视图模型获取值

无法插入 LayoutNode@cc72396 子级,因为它已有父级

在 react native 中设置 react-native-paper 组件的样式

Jetpack compose :使用 rememberSaveable 时未应用待处理的合成

在事件中使用 Context/Toast 时不需要的重组 - Jetpack Compose

如何使用 Jetpack Compose 在图像上叠加文本

Android collectAsStateWithLifecycle() 不在可组合内部收集

自定义 Compose Arrangement 以在 LazyRow/LazyColumn 的开头和结尾添加额外的间距

Android Compose 创建抖动动画

运行一次 kotlin 流,但在下游收到两次

在 compose 屏幕之间传递 uri 会导致:SecurityException: Permission Denial