我正在开发一个使用dagger2来解决依赖关系的Android应用,但出现了编译错误。
请在下面找到我的体系结构:
Android模块依赖项:
和我的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)
任何人都可以帮助我解决此问题吗?
请注意,我正在混合Kotlin和Java。我不知道这是否重要