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
Include on your module the dependency module like this:
What you want to be determined to be within the
ApplicationScope
should be all defined without a scope, and linked together under the application scope only in theApplicationComponent
under the given scope.For example,
Then you can do
After which you can do
Please note that unscoped providers create a new instance on every inject call. If you need the scoping, you should bind the modules to the same component, but components should only depend on other components with the intention of subscoping.
You can't use scoped components in a dependencies array (which is quite strange I have to say), only unscoped, or one scoped + other unscoped. But you can deceive dagger with "proxy" interfaces:
But in your ComponentC builder you should use proxy components implementations, which could easily be achieved with Kotlin:
Works on dagger version 2.13, don't know about others
Also you could use vice versa inheritance ComponentA : ProxyComponentA to eliminate the need to create ProxyComponentAImpl, but it's not a good design choice if your ComponentA lays for example in a different gradle module
The solution was inspired by that issue discussion: https://github.com/google/dagger/issues/1225
I found the answer here: https://stackoverflow.com/a/29619594/1016472
At the end I created a AppComponent with the right scope and let FacebookComponent and AnotherComponent extends this AppComponent.
FacebookComponent and AnotherComponent does not have it's own scope (I removed it).
Looks now like this: