I have a RepositoryActual and RepositoryInterface. I want to use RepositoryInterface at all of my call sites, but I want RepositoryActual to be created. Do I need to use a @Provides method, or can I do this with an @Inject annotation? (basically trying to see if I can spare myself having to create a @Module)
p
Paul Woitaschek
11/14/2021, 7:31 PM
You usually want to add an inject annotation to the constructor and use a binds in a module to bind the impl to the interface.
If you use anvil you can use the contributesBinding annotation and let it generate the binding module and the glue for you
👍 1
c
Colton Idle
11/14/2021, 7:32 PM
Don't use anvil. And okay... I will try the @Inject on the concrete constructor, and use @Binds in the module.
Thanks
p
Paul Woitaschek
11/14/2021, 7:33 PM
I really can recommend anvil, it decouples your code and makes dagger so easier to use
👀 1
🙏 1
Else you always have to touch multiple classes for a simple dependency
c
Colton Idle
11/14/2021, 7:41 PM
I have looked into it, but I am trying to grasp dagger well first. I still have so many issues and "analysis paralysis" when it comes to even just adding simple/commons dependencies.
p
Paul Woitaschek
11/14/2021, 7:55 PM
Then the pro tip is to take a look at the generated code :)