[英]Inject interface in constructor of usecase
我有一個界面:
interface CartonRepository {
fun addToCart(company: Company): Completable
}
現在,我想在用例中使用此接口:
class ObserveCartonItemSelectionUseCase
@Inject constructor(private val cartonRepository: CartonRepository) : ObservableUseCase<UUID, Boolean> {
}
並且此用例通過以下方式注入到其他類中:
@Inject
protected lateinit var observeCartonSelectionUseCase: ObserveCartonItemSelectionUseCase
我收到一個錯誤:
ApplicationComponent.java:13: error: CartonRepository cannot be provided without an @Provides-annotated method.
public abstract void inject(@org.jetbrains.annotations.NotNull()
該錯誤說明要提供CartonRepository
到底應CartonRepository
。 在您的界面中添加@Provides
批注:
@Provided
interface CartonRepository {
fun addToCart(company: Company): Completable
}
這將告訴Dagger該接口應該是可注入的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.