Can Dagger inject an abstract activity class without injecting a child activity class?

I am trying to implement Dagger in my application and I have an instance where I need to inject a field into a class in the hierarchy of the Activity class, but the children of that class do not need any injected members. The hierarchy looks like this:

BaseActivity -> NavigationActivity -> HomePageActivity.

I am trying to enter a field in NavigationActivity, but I am getting the following exception from Dagger:

java.lang.IllegalArgumentException: No inject registered for members/com.quidsi.diapers.activity.HomePageActivity. You must explicitly add it to the 'injects' option in one of your modules.

      

My module looks like this

@Module(
    injects = NavigationActivity.class
)
public class GestureModule {

    @Provides
    GestureInterface provideGestureInterface() {
        return new MockDrawerGesture();
    }
}

      

Is this possible with a dagger or do I have to inject every child of the NavigationActivity?

+3


source to share


1 answer


This is not possible with dagger 1. You will also have to enter subclassed actions. And yes, unfortunately, this means that you have to add all of these classes to the injection list in your GestureMmodule.



Dagger 2 is just around the corner, maybe something has changed there.

+2


source







All Articles