I am working on a new app and I am planning to use...
# android-architecture
s
I am working on a new app and I am planning to use dagger. I am specifically interested to know your thoughts on dagger components. 1. Should I create components based on the lifecycle of their use case. For example, a component for all objects when the user is logged in? I am confused about how to structure my components. 2. Where should components be stored? For example, for the user logged in component, where do I store the component? 3. How do I dispose of components? Is setting it to null enough? I am having a hard time, how many components to create and for what use cases. Please assist. If there is a better channel for this question let me know.
a
Which usecase is stopping you from using hilt ? is it because you want components feature-wise and not layer-wise ?
s
I am not interested in using hilt.
a
Ideally you would have 1 component per activity and not feature . you can have feature wise components which are marked as dependencies on your activity components (marked as dependencies in ActvityComponent , not by using SubComponents ).
s
Thanks. I was planning on creating activity subcomponents whose parent will an app component, providing app wide dependencies.
What do you think?
a
You will have issues modularizing the app then if you use subcomponents
s
Why would that be the case?
a
Subcomponents keeps the components coupled
s
Ok. " feature wise components which are marked as dependencies on your activity components" is this accomplished by using creating Dagger modules?
No prob. I checked the so thread, they have the info. Thanks
a
So lets say you have onboarding feature , common classes like your APIs DBs etc specefic to this feature will be provided by a OnboardingComponent (this component has its own modules which provide your APIs DBs etc) , Now lets say in OnboardingFeature you have SignUpActivity , SignUpComponent will have dependency on OnboardingComponent to provide all the APIs DBs .
s
So you are saying having a component dependency will support modularization while subcomponents will prevent it right?
a
Yes
s
So if i have two feature modules, A and B. B depending on A, how will it work?
a
Hilt is the best if you want to modularize , but keeping feature wise components is a pain
feature modules should not depend on each other
s
Let say A is a platform module while B is a feature module
I would want networking apis part of A in B. Should i use component dependecy here? Will it work
a
Yes , will work fine
in B’s component you add dependency for A’s component
s
Any resources to learn this in more detail?
Most posts online are rudimentary, so not very helpful
a
I have learned most of this by looking at all my companies code only so I do not have resource for you unfortunately
s
Cool, thanks for your help
a
I would still say try out hilt , it makes lot of stuff easier