Ошибка компиляции Dagger2: невозможно предоставить без аннотируемого метода @ Provides - PullRequest
0 голосов
/ 16 октября 2018

Я разрабатываю приложение для Android и использую dagger2 для устранения зависимостей, но получаю ошибку компиляции.

Ниже приведена моя архитектура:

Зависимости модуля Android:

enter image description here

и моя конфигурация dagger2:

@Singleton
@Component(modules = [ApplicationModule::class])
interface ApplicationComponent {
  fun presenterComponentBuilder(): PresenterBuilder.Builder
  fun useCaseComponentBuilder(): UseCaseComponent.Builder
  fun authenticationComponentBuilder(): AuthenticationComponent.Builder

затем первый подкомпонент

@PresenterScope
@Subcomponent()
interface PresenterComponent {
  @Subcomponent.Builder
  interface Builder {
    fun build(): PresenterComponent
  }

  fun inject(signUpViewModel: SignUpViewModel) //compilation error
}

Другой подкомпонент:

@UseCaseScope
@Subcomponent(modules = [AuthenticationUseCaseModule::class])
interface UseCaseComponent
{
  @Subcomponent.Builder
  interface Builder {
    fun requestAuthenticationUseCasemodule(module: AuthenticationUseCaseModule): Builder
    fun build(): UseCaseComponent

}

с его модулем

@Module(subcomponent = [AuthenticationComponent::class])
class AuthenticationUseCaseModule{
  @UseCaseScope
  @Provides
  fun provideRequestSignUpUseCase(authenticationService: AuthenticationService)= RequestSignUpUseCase(authenticationService)

И последний компонент

@AuthenticationScope
@Subcomponent(modules = {AuthenticationModule.class})
public interface AuthenticationComponent {    
  @Subcomponent.Builder
  interface Builder {
    Builder authenticationModule(final AuthenticationModule authenticationModule);    
    AuthenticationComponent build();
  }
}

с его модулем

@Module
public class AuthenticationModule {
  @Provides
  @AuthenticationScope
  public AuthenticationService provideAmazonCognito(final Context context){return AmazonCognito(context);
}

Когда я пытаюсь скомпилировать мой код, я получаю:

PresenterComponent.inject(SignUpViewModel) AuthenticationService cannot be provided without an @Provides-annotated method.
public abstract interface ApplicationComponent {
                ^
      AuthenticationService is injected at
          RequestSignUpUseCase.<init>(arg0)
      RequestSignUpUseCase is injected at
      SignUpViewModel.requestSignUpUseCase
      SignUpViewModel is injected at
      PresenterComponent.inject(arg0)

Кто-нибудь может помочь мне решить эту проблему, пожалуйста?

Обратите вниманиеЯ смешиваю Котлин и Яву.Я не знаю, имеет ли это значение

...