CustomView dependency injection with dagger 2 (within activity scope)

前端 未结 2 1422
广开言路
广开言路 2021-02-02 13:04

My question is similar to this.

So for instance, I have a LiveData implementation:

public class CustomLiveData extends LiveData

        
2条回答
  •  我在风中等你
    2021-02-02 13:52

    Your Dagger hierarchy looks like this: appcomponent -> activitycomponent

    You try to inject activity context inside view, that depends on appcomponent directly.

    It's not possible since there is no method that could provide activity context in appcomponent. Instead, inside view, you should retrieve activity (for example using getContext), extract activitycomponent from it and only then inject CustomLiveData.

提交回复
热议问题