Search code examples
androiddependency-injectiondagger-2dagger

Dagger does not throw exception if a subcomponent has conflicting scope with one of the parent components


ComponentA (scopeA)
ComponentB (scopeB, dependencies = ComponentA)
ComponentC (scopeC, dependecies = ComponentB)
SubcomponentD (scopeA, created from ComponentC).

No exception is thrown though D has conflict with A (code)

If we leave only ComponentA (scopeA)
SubcomponentD (scopeA, created from ComponentA)
then the conflicting scopes exception will be thrown.

Why in the first case no exception thrown?

I created an issue but no answer yet.


Solution

  • I got it. A subcomponent is a part of its parent component (not any ancestor subcomponent). So Dagger checks the scopes hierarchy for each component (not for the whole graph). See here.