This is what I currently have and it works:
@FragmentScope
@Component(dependencies = {FacebookComponent.class},
modules = {FragmentFacebookLoginModule.class})
public interface FragmentFacebookLoginComponent {
void inject(FragmentFacebookLogin fragment);
}
Now I want to add another dependency. I changed it to this:
@Component(dependencies = {FacebookComponent.class, AnotherComponent.class},
modules = {FragmentFacebookLoginModule.class})
But now I get this error message:
FragmentFacebookLoginComponent depends on more than one scoped component
How can I solve this? How can I have more than one dependencies?
If I remove the scope from one component I get this error message:
AnotherComponent (unscoped) cannot depend on scoped components
There are two options. Component dependencies. This option migrated from Dagger 1. Let’s denote Component dependencies traits right away: Two dependent components cannot have the same Scope. Parent component must explicitly declare objects which can be used in child components. Component can depend on other components.
This one was introduced in Dagger 2. Parent component is obliged to declare Subcomponents getters inside its interface. Subcomponent has access to all parents objects. Subcomponent can only have one parent. Surely Subcomponents have differences from Component Dependencies. Let’s look into scheme and code to get this clear.
Dagger 2. Part II. Custom scopes, Component dependencies, Subcomponents Dagger 2 articles cycle: Dagger 2. Part I. Basic principles, graph dependencies, scopes. Dagger 2. Part II. Custom scopes, Component dependencies, Subcomponents. Dagger 2. Part three.
While there are other Java dependency injection frameworks, many of them suffered limitations in relying on XML, required validating dependency issues at run-time, or incurred performance penalties during startup. Dagger 2 relies purely on using Java annotation processors and compile-time checks to analyze and verify dependencies.
Now Dagger supports a component that can depends on more than 1 scoped dependencies. Just update your dagger version to 2.27
https://github.com/google/dagger/issues/1414
api 'com.google.dagger:dagger:2.27'
kapt 'com.google.dagger:dagger-compiler:2.27'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With