1

I have problem with member injecting interface type.

Here is example: I have interface let's call it BookActivity

interface BookActivity {}

it's simple marker interface that do nothing.

and I have two implementation:

BookNewActivity: Activity, BookActivity {

    @Inject someField: SomeField;

    override fonCreate(savedInstanceState:Bundle?) {
        activityComponent.inject(this)
    }

}

BookOldActivity: Activity, BookActivity {
    @Inject someField: SomeField;

override fonCreate(savedInstanceState:Bundle?) {
        activityComponent.inject(this)
    }
}

interface ActivityComponent {
    fun inject(BookActivity)
}

When I try to get access to someField I get NPE because dagger did not inject SomeField in my class. How can I solve this problem?

d.popovych
  • 359
  • 1
  • 3
  • 9

1 Answers1

0

Not sure, but this will be probably problem with dagger understanding the parent interface. You can try to have 2 inject methods for each Activity.

If an interface could have properties, you could have it there, but that's not possible :(

mlykotom
  • 4,850
  • 1
  • 22
  • 27