Eido95
Eido95

Reputation: 1383

Is it possible to inject subcomponent dependency into parent component?

Consider I have the following object graph:

SessionComponent dependencies are being created (injected) at each session start.

Is it possible to inject @SessionScope dependencies (provided at SessionComponent) into @AppScope dependencies (provided at AppComponent)?

Vice versa is possible, as mentioned in Component documentation:

The simplest way to relate two components is by declaring a Subcomponent. A subcomponent behaves exactly like a component, but has its implementation generated within a parent component or subcomponent. That relationship allows the subcomponent implementation to inherit the entire binding graph from its parent when it is declared.

I found that programmatically it is possible using this approach, but is it possible to do using only Dagger API?

Upvotes: 0

Views: 274

Answers (1)

Benjamin
Benjamin

Reputation: 7368

No, you can't:

Bindings that are installed into a component can not see bindings from its subcomponent. Instead, it's the other way around: bindings in a subcomponent can depend on bindings in a parent component.

as stated in this answer from your link.

Upvotes: 1

Related Questions