Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make UserComponent be Sub Component of another one? #22

Open
IHNEL opened this issue Apr 22, 2017 · 4 comments
Open

Make UserComponent be Sub Component of another one? #22

IHNEL opened this issue Apr 22, 2017 · 4 comments

Comments

@IHNEL
Copy link

IHNEL commented Apr 22, 2017

Thank you for your sharing this tutorial, it s very helpful

I am using your idea about User Scope to share signed user instance across it's sub components. And I want to make UserComponent itself be sub component of another one, like Base Activity Component.
My graph is
App component > base activity component > User Component > User Details Component (and many others)

The arrow stands for sub-component relationship.
In your example, you used SubComponent Builder to create User component, how can i make it extends all resource provide by App component and Base Activity component?

@smithc42
Copy link

Did you figure this out? I'm interested in ways to create App component > Activity Component > Fragment Component relationship!

@IHNEL
Copy link
Author

IHNEL commented May 26, 2017

@smithc42 Yes, I investigate again and again his post here: http://frogermcs.github.io/building-userscope-with-dagger2/, and then I apply similar way to my application. using @Subcomponent.Builder I can make a component be subcomponent of any other one.

For the relationship App component > Activity Component > Fragment Component , it's easy to achieve by define the <Component> plus( <module>) function in the parent component interface, once you have the parent component instance, just call this method and supply the sub-module instance, you will got new sub-component and it inherits all properties of its parents.

For more details, read this post: http://frogermcs.github.io/dependency-injection-with-dagger-2-custom-scopes/

if you are unable to build this in practices, share me the sample git and I can help.

@smithc42
Copy link

@IHNEL Thanks for the reply. I managed to set it up correctly but Dagger kept throwing:

...dependency cannot be provided without an @provides-annotated method...a binding with matching key exists in MainComponent

I finally figured out I forgot to remove void inject(MainFragment fragment) from the root component (legacy code). Once I removed the injection from the root component it worked as expected.

Cheers!

@IHNEL
Copy link
Author

IHNEL commented May 27, 2017

the message from Dagger is very clear. you inject a class into somewhere but didn't define @Provide method or inject constructure

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants