I am using dagger2 to manage the dependencies , is...
# android
c
I am using dagger2 to manage the dependencies , is it possible to inject dependencies in different modules. Suppose I have set up dagger two in app and if I want to use the same dependency in a module login?
👍 2
stackoverflow 5
a
yes
as long as that dep is on classpath and the modules tie up into a common component class, youll all good
and one of those modules provide the dependency
c
I cannot access the dagger generated code in my login module, is there any resources I can read so that I can solve this issue?
a
You shouldn't access any dagger generated code in your modules except the generated dagger component if you need it. But that shouldn't be necessary in a library module
c
That's what I am trying to accomplish but I am unable to, here is the repo if it helps https://github.com/dilipMaharjan/DaggerTwoAndroid I am trying to get the User in data package to be used in login module.
a
the example login does not provide any dependencies or use dagger at all
c
The idea is to inject User object which I get from app to LoginActivity which is what I am trying to accomplish @agrosner.Questions: Am I trying to do it right? Is there a better way to accomplish it?
a
you need to place user object in login module or in another submodule that login inherits from
c
How does it help to accomplish injection between different modules?I haven't found any resource that explains where I can inject between modules. It would be helpful if you could elaborate or point me to an example. Thank you so much for taking time to help me out.
a
np. just create a dagger
@Module
for Login. include that in the appcomponent in your project. make a
@Module
per submodule you need that supply dependencies. if you need to inject
User
you need to place that object either in the
Login
module where you can
@Inject
it or in its own
@Module
inherited by both app and login projects
c
Could you please modify my repo or create an example app?
s
you can take a loot at this for reference: https://github.com/cerberusv2px/android-dagger-support
c
@sujin When I said module, it meant android modules not different packages(android lib modules)
a
theres plenty of examples online. I won't do the work for you 😛
c
I am sorry but not trying to make you work for me. I am trying to learn that's all. I am so far to communicate between the modules with new annotations but I am stuck as I am unable to understand how to inject object with Constructor parameter such as User("username","password") . For reference here https://github.com/dilipMaharjan/DaggerTwoAndroid/tree/dagger-two-with-new-annotations
s
do you mean injecting data module and the login module ?
c
@sujin I could get the injection working with new annotations but I could only inject string as I was trying out example but I want to inject the User object where I am having difficulty.This is the repo ( https://github.com/dilipMaharjan/DaggerTwoAndroid/tree/dagger-two-with-new-annotations) if it helps, where I am trying to inject User object from data module to login module