Integrating multi scope dagger 2 components

2019-07-24 17:08发布

问题:

Preconditions

I have the following components:

  1. ApplicationCompoennt - With @ApplicationScope - This component contains LogModule. The logmodule @Provides Logger.
  2. ActivityComponent with @ActivityScope - This component contains MyActivityModule. Since one can't call the ctor of Activity explicitly, this module is used to inject the activity. This component depends on @ApplicationScope component, to use the Logger.
  3. BroadcastComponent with @BroadcastReceiverScope - This component contains BroadcastReceiverModule. Since one can't call the ctor of it explicitly (its present in the Android manifest file), this module is used to inject the broadcast receiver.

Problem:

I cant create ActivityComponent with 2 dependencies namely ApplicationComponent and BroadcastComponent, they being of different scopes, as we cant have dependent components of different scopes

How to get around this problem ?