https://kotlinlang.org logo
Title
c

crazdrms

04/16/2018, 5:46 PM
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?
:stackoverflow: 5
👍 2
a

agrosner

04/16/2018, 7:43 PM
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

crazdrms

04/16/2018, 8:13 PM
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

agrosner

04/16/2018, 9:02 PM
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

crazdrms

04/17/2018, 12:33 PM
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

agrosner

04/17/2018, 7:35 PM
the example login does not provide any dependencies or use dagger at all
c

crazdrms

04/17/2018, 7:57 PM
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

agrosner

04/17/2018, 8:08 PM
you need to place user object in login module or in another submodule that login inherits from
c

crazdrms

04/17/2018, 8:15 PM
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

agrosner

04/17/2018, 8:31 PM
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

crazdrms

04/17/2018, 8:36 PM
Could you please modify my repo or create an example app?
s

sujin

04/25/2018, 9:06 AM
you can take a loot at this for reference: https://github.com/cerberusv2px/android-dagger-support
c

crazdrms

04/25/2018, 12:16 PM
@sujin When I said module, it meant android modules not different packages(android lib modules)
a

agrosner

04/25/2018, 1:47 PM
theres plenty of examples online. I won't do the work for you 😛
c

crazdrms

04/25/2018, 1:53 PM
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

sujin

04/25/2018, 2:45 PM
do you mean injecting data module and the login module ?
c

crazdrms

04/25/2018, 3:10 PM
@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