Migrate existing dagger tree in multi module with deep Subcomponent Tree #739
-
|
Hi! I wanted to ask for help because I'm a bit stuck migrating our anvil tree to metro: We have the following structure:
We'd like to have AppComponent-ActivitySubComponent1-FragmentSubComponent1, etc chains. So far we could achieve this by not using Now with Graph extensions the direction changes. We cannot reference Is there a way to solve this structure? Bonus question: In |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 10 replies
-
It should be possible to use ContributesGraphExtension on the contributed graph and then manually make the target graph implement its factory (rather than contributing its factory to a general scope) @ContributesGraphExtension(...)
interface FragmentSubComponent1 {
interface Parent {
...
}
}
interface ActivitySubComponent1 : FragmentSubComponent1.ParentThe parent graph processing should recognize that Parent's inherited creator function returns a contributed graph and thus create the graph still. Somewhat similar to how Dagger will special-case accessors that return subcomponents or subcomponent creators. This isn't a case with a test currently though so let me know if you have any issues where we need to maybe relax some constraints or make this easier. |
Beta Was this translation helpful? Give feedback.
-
Yes and no! Replacements are only for excluding other contributions and injected classes are not inherently contributions. That said, this case will actually still work the way you want because you are adding an explicit provider of that class, which will short-circuit the lookup of the class's injectable constructor. |
Beta Was this translation helpful? Give feedback.
It should be possible to use ContributesGraphExtension on the contributed graph and then manually make the target graph implement its factory (rather than contributing its factory to a general scope)
The parent graph processing should recognize that Parent's inherited creator function returns a contributed graph and thus create the graph still. Somewhat similar to how Dagger will special-case accessors that return subcomponents or subcomponent creators.
This isn't a case with a test cu…