0

I have an interface:

interface CartonRepository {
    fun addToCart(company: Company): Completable
}

Now I want to use this interface in my use case:

class ObserveCartonItemSelectionUseCase
@Inject constructor(private val cartonRepository: CartonRepository) : ObservableUseCase<UUID, Boolean> {

}

and this use case is injected in other class by:

@Inject
protected lateinit var observeCartonSelectionUseCase: ObserveCartonItemSelectionUseCase

I get an error:

ApplicationComponent.java:13: error: CartonRepository cannot be provided without an @Provides-annotated method.
    public abstract void inject(@org.jetbrains.annotations.NotNull()
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
edi233
  • 3,511
  • 13
  • 56
  • 97
  • So where do you define which `CartonRepository` to use? You need a module to bind it somewhere! Please also see [how to fix cannot be provided](https://stackoverflow.com/a/44912081/1837367) – David Medenjak May 15 '18 at 07:48

1 Answers1

0

The error says exactly what should be done to provide the CartonRepository. Add a @Provides annotation to your interface:

@Provided
interface CartonRepository {
fun addToCart(company: Company): Completable

}

That will tell Dagger that this interface should be injectable.

Rafal Zawadzki
  • 963
  • 6
  • 15
  • 1
    I can't do that. I use clean architecture and this interface is in domain module as a ObserveCartonItemSelectionUseCase. Domain module don't have Dagger dependency so I don't have @Provided annotation. I can't move interface to presentation module where I have dagger because domain cannot have dependency to presentation module – edi233 May 15 '18 at 07:14