I have a Dagger Subcomponent called UserComponent
, created when a user signed in to the app, beneath that I have lists of Subcomponents
(e.g : FriendsComponent, ProfileComponent, HomeComponent ...).
What I want is this: creating a subComponent called ProfileComponent
(under UserComponent) that got two Modules ProfileModule
and PostsModule
:
MainComponent
|
=============|======================
| |
| |
UserComponent WelcomeComponent
|
=========|============
| |
ProfileComponent HomeComponent
|
|
=====================
| |
PostsModule ProfileModule
(I hope this is readable )
so ProfileComponent shall contains this :
@UserScope
@Subcomponent(
modules = {PostsModule.class, ProfileModule.class}
)
public interface ProfileComponent {
void inject(PostsFragment postsFragment);
void inject(ProfileActivity profileActivity);
}
Here is the User SubComponent
@UserScope
@Subcomponent(
modules = UserModule.class
)
public interface UserComponent {
HomeComponent plus(HomeModule homeModule);
ProfileComponent plus(PostsModule postsModule);
ProfileComponent plus(ProfileModule profileModule);
}
Injection done here, in PostsFragment
protected void setUpComponent(DragonBloodComponent component) {
mApp.getApp(getActivity()).getUserComponent()
.plus(new PostsModule())
.inject(this);
}
I get this error
error: Only one method can create a given subcomponent..profile.ProfileComponent is created by: [plus(PostsModule), plus(ProfileModule)]
Am I doing this right? Thank you.