google / dagger

A fast dependency injector for Android and Java.
https://dagger.dev
Apache License 2.0
17.42k stars 2.01k forks source link

com.google.dagger:dagger-android forces an unwanted/wrong dependency #678

Closed sergejsha closed 7 years ago

sergejsha commented 7 years ago

Just tried the new "dagger-android" module and found out, that it forces me to add a dependency between Gradle modules in my project, which is unwanted or even wrong.

I use dagger2 in a player app, which consists of 3 modules: 'UI' module, 'Service' module and 'App' module. 'UI' module contains all UI's of the player like activities, fragments etc. 'Service' module contains headless (no UI) implementation of the playback logic. 'App' module contains the code shared between the 'UI' and the 'Service' modules (app, content providers, network modules etc). When launched, the UI and Service modules run in two separate processes to ensure clear separation and independence of UI and player parts.

Now, the 'App' module contains App and AppComponent classes. In my initial design App had no dependency on Activities. In contrast, the Activities used AppComponent for injection. Thus the dependency was from 'UI' to 'App'. After trying out "dagger-android" I realized, that I have to reference each ActivityModule in the AppComponent in order to get DispatchingAndroidInjector populated. This forces me to add this unwanted dependency I am talking about.

Can you guys think of any possible option letting me to use "dagger-android" but avoid app to ui compile dependency? Or any other solution for this case?

ronshapiro commented 7 years ago

This sounds like a post that's better fit for stack overflow