JakeWharton/u2020

How to use dagger-compiler validation with current architecture of injection?

Closed this issue · 4 comments

Hello @JakeWharton. I am trying to implement compile-time assertable Dependency Injection using Dagger.

Your injection architecture seems better than usage of Scoped Graphs when we use one objectGraph but adding required modules using objectGraph.plus(modules) from each place where we need an injection.

But, both of architectures (Your: with one Module which includes other modules and Scoped Graphs) are not supported by dagger-compiler..

For example, try to remove MainActivity.class from injects of UiModule and code will be compilable, but you'll got this at runtime:
java.lang.IllegalArgumentException: No inject registered for members/com.jakewharton.u2020.ui.MainActivity. You must explicitly add it to the 'injects' option in one of your modules.

Is there an option to use one ObjectGraph and have validation of injects declarations from dagger-compiler?

Also, as I understand, @cgruber can help with this :)

Or you could wait about two weeks and start trying out Dagger 2.x which is
entirely 100% compile-time dependency injection. :D

On Fri, Aug 29, 2014 at 1:58 AM, Artem notifications@github.com wrote:

Hello @JakeWharton https://github.com/JakeWharton. I am trying to
implement compile-time assertable Dependency Injection using Dagger.

Your injection architecture seems better than usage of Scoped Graphs when
we use one objectGraph but adding required modules using
objectGraph.plus(modules) from each place where we need an injection.

But, both of architectures (Your: with one Module which includes other
modules and Scoped Graphs) are not supported by dagger-compiler..

For example, try to remove MainActivity.class from injects of UiModule
and code will be compilable, but you'll got this at runtime:
java.lang.IllegalArgumentException: No inject registered for
members/com.jakewharton.u2020.ui.MainActivity. You must explicitly add it
to the 'injects' option in one of your modules.

Is there an option to use one ObjectGraph and have validation of injects
declarations from dagger-compiler?

Also, as I understand, @cgruber https://github.com/cgruber can help
with this :)


Reply to this email directly or view it on GitHub
#32.


Christian Gruber
christianedwardgruber@gmail.com

@cgruber would be great, I am waiting for Dagger2 in the Maven Center :)

Hopefully we can have a snapshot within the next two weeks or less.

On Mon, Sep 1, 2014 at 4:27 PM, Artem notifications@github.com wrote:

@cgruber https://github.com/cgruber would be great, I am waiting for
Dagger2 in the Maven Center :)


Reply to this email directly or view it on GitHub
#32 (comment).


Christian Gruber
christianedwardgruber@gmail.com

The example you gave cannot be validated with the current configuration. If you do something more drastic like delete UiModule from the includes= of U2020Module it will fail the build.