私はプロジェクトでダガー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()
ダガー2の問題:@Providesメソッドなしでは提供できません
私はトピックについて研究しようとしましたが、私のコードの間違いを正確に指摘できませんでした。私はどこかで小さな間違いをしたと思うか、Dagger2で何か間違ったことを理解していた2。誰かが間違いを指摘できれば。私は本当にそれを感謝します。
私のマネージャー
public interface MyManager {
Observable<User> getAllUsers();
}
SIGNINプレゼンター
@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
。どんな提案アドバイスも高く評価されます。 :)