Components with multiple scoped dependencies

272 views
Skip to first unread message

Cesar Puerta

unread,
May 5, 2016, 3:15:57 PM5/5/16
to Dagger Discuss
Hi,

The original proposal for Dagger 2 (here) establishes that a component may only have one scoped dependency, in order to guarantee the singleton restriction on every nested scope:
  • A scoped component may only have one scoped dependency.  This is the mechanism that enforces that two components don’t each declare their own scoped binding.  E.g. Two Singleton components that each have their own @Singleton Cache would be broken.
It seems to me, however, that it would be enough with guaranteeing that a component can't reach two components in the same scope through its transitive dependencies. Dagger 2 already does a similar check to ensure that scopes are not duplicated in the chain of dependent scopes. Also, allowing multiple scoped dependent components would enable dependencies with multiple independent scoped graphs and encourage the decomposition of large graphs.

What is the reason for this restriction? Is there a chance that the rule may be relaxed in future releases of Dagger 2?

Thanks,
César
Reply all
Reply to author
Forward
0 new messages