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)
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
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.
11/14/2021, 7:33 PM
I really can recommend anvil, it decouples your code and makes dagger so easier to use
Else you always have to touch multiple classes for a simple dependency
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.
11/14/2021, 7:55 PM
Then the pro tip is to take a look at the generated code :)