google/dagger

Support dependency cycles containing Lazy or Provider

kotucz opened this issue · 2 comments

Dagger 2.0 currently does not support any kind of dependency cycles. Dagger 1 allowed this using Lazy<T> or Provider<T> dependency wrapper. An issue for this was started here: #45
Which was solved only by throwing compile time error when such dependency cycle occurs.
As mentioned here: #45 (comment) this makes dagger2 not JSR 330 compliant.

I have checked the generated code and modified it to work in and example. So I think the code generation for dagger2 could be modified to allow dependency cycles containing Lazy or Provider.
The generated code modification is described in example here:
https://github.com/kotucz/dagger-lazy-cycle

There is no technical reason that dependency cycles (when moderated by indirection from Lazy or Provider) could not be supported. Dependency cycles were disallowed as a design choice for Dagger 2. We're examining the implications of this w.r.t. the JSR-330 specification.

At this point, the TCK is stricter than the formal specification in the javadocs, as far as I can tell. That either means that the JSR is incompletely specified and its TCK is correct, or that it is fully specified and the TCK is overzealous or incorrect in its testing. I'm not sure which is the case, and that may take some clarification with the specification authors.

This should be a point for clarification in any revision to the specification.

After some discussion, we've decided this should be implemented, to keep consistent with the JSR.

The plan of record is to turn the error into a warning (since we still think that cycles are, with rare exceptions, code smells), but permitted with the hege of Lazy/Provider indirection.