Can I just inject super class when use dagger2 for dependency injection?

后端 未结 3 951
你的背包
你的背包 2020-12-04 16:57

I use Dagger2 for DI in my android application. I found that I have to write inject method for every class that uses @Inject field. Is there a way that I can just inject the

3条回答
  •  抹茶落季
    2020-12-04 17:11

    It cannot be done right now. Explanation by Gregory Kick (from here):

    Here's how members injection methods work:

    1. You can make a members injection method for any type that has @Inject anywhere in its class hierarchy. If it doesn't, you'll get an error.
    2. All @Injected members in the entire type hierarchy will be injected: the argument type and all supertypes.
    3. No members will be @Injected for subtypes of the argument type.

    This issue was discussed here and here, follow up these for updates. But it is unlikely to change soon, cause Dagger 2 is close to release.

提交回复
热议问题