[英]Koin Android-KMM: I have nested scopes but injection is not working
我收到此错误。 我正在使用 Koin 进行依赖注入。 我希望我的约会存储库是活的,因为 UserInfoContainer scope 是活的。 找不到 class 的定义:'com.flow.domain.repository.AppointmentsRepository'。 检查你的定义!
用户信息容器 class
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 }
)
}
}
约会用例 class
class AppointmentsUseCase : KoinComponent {
private val appointmentsRepository: AppointmentsRepository by inject()
suspend fun getAppointments(startDate: LocalDateTime, endDate: LocalDateTime): List<Appointment> =
appointmentsRepository.getAppointments(startDate, endDate)
}
这就是我应该如何在用例中注入我的依赖项
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)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.