Activity Graphs And Non-found Dependency
I'm starting using the dagger, like it pretty much, but now facing some difficulties. My scenario is as follows: there's an activity and a dependency for it. Dependency is injected
Solution 1:
I'm no Dagger expert, but you have 2 issues:
- you have a cyclical dependency: you helper want to have the activity injected, your activity wants to have the helper injected. I don't think Dagger can resolve this
- your activity tries to get injected twice, once with the activity-level graph, once with the application-level graph
Here's what I did to get it to work:
- in ScbeHelper: remove the @Inject annotation
- in BaseActivity: remove ((protoApp)getApplication()).inject(this);
- in ActivityModule: remove your provideActivity method (it's not going to be used anymore), and add the following method:
@Provides@Singleton ScbeHelper provideScbeHelper() {
returnnewScbeHelper(activity);
}
What this does is it provides your ScbeHelper with the context it needs, but leaves only 1 annotation-driven injection so dagger can resolve it. Hope this helps.
Post a Comment for "Activity Graphs And Non-found Dependency"