Dagger 2 问题:没有 @Provides 方法就无法提供

Dagger 2 issue: cannot be provided without a @Provides method

我在我的项目中玩 Dagger 2,然后我陷入了这个错误编译。 -> Error:(18, 21) error: ....MyManager cannot be provided without an @Provides-annotated method. ...MyManager is injected at ...SignInPresenter.<init>(myManager) ...SignInPresenter is provided at ...SignInComponent.signInPresenter()

我试图研究这个主题,但我无法准确指出我的代码中的错误。我想我在某个地方犯了一个小错误,或者我对 Dagger2 的理解有问题。如果有人能指出错误。我会很感激的。

我的经理

public interface MyManager {
    Observable<User> getAllUsers();
}

登录演示者

 @Inject
    public SignInPresenter(MyManager myManager) {
        this.myManager= myManager;
    }

我在 MySignInFragment

中做了类似的事情
   @Override protected void injectDependencies() {
        signInComponent = DaggerSignInComponent.builder()
                .myApplicationComponent(MyDaggerApplication.getMyComponents())
               .build();
    }

登录组件

@Component(modules = {MyModule.class},
        dependencies = {MyApplicationComponent.class})
public interface SignInComponent {
    SignInPresenter signInPresenter();
}

这是我的应用程序

public class MyDaggerApplication extends Application {
    private static MyApplicationComponent myApplicationComponent;


    @Override
    public void onCreate() {
        super.onCreate();
        myApplicationComponent = DaggerMyApplicationComponent.create();
        myApplicationComponent = DaggerMyApplicationComponent.builder().myModule(new MyModule(this)).build();
        myApplicationComponent.inject(this);
    }

    public MyApplicationComponent getMyAppComponents(){
        return myApplicationComponent;
    }

    public static MyApplicationComponent getMyComponents(){
        return myApplicationComponent;
    }
}

我的模块和组件类

@Component(modules = {MyModule.class})
public interface MyApplicationComponent {
    void inject(MyDaggerApplication myDaggerApplication);
}

@Module
public class MyModule {
    private final MyDaggerApplication myDaggerApplication;

    public MyModule(MyDaggerApplication myDaggerApplication){
        this.myDaggerApplication = myDaggerApplication;
    }

    @Provides
    @Singleton
    Context providesApplicationContext() {
        return this.myDaggerApplication;
    }

    @Provides
    @Singleton
    SharedPreferences providesSharedPreferences(Context context) {
        return context.getSharedPreferences("My_Pref", Context.MODE_PRIVATE);
    }

    @Provides
    @Singleton
    public MyDefaultManager providesMyDefaultManager(MyDefaultManager myDefaultManager,Context context){
        return myDefaultManager.getInstance(context);
    }
}

我猜我在 DaggerApplication 中做错了什么。任何建议意见将不胜感激。 :)

假设 MyDefaultManager 实现 MyManager,将 MyModule 中的最终提供者更改为:

@Provides
@Singleton
public MyManager providesMyDefaultManager(MyDefaultManager myDefaultManager,Context context){
    return myDefaultManager.getInstance(context);
}

正如您想要 return ? implements MyManager 的一个实例,而不是 MyDefaulManager 具体。