Sobes.tech
Middle+

Why use Binds if Provide already exists?

sobes.tech AI

Answer from AI

@Binds is used to bind an interface or abstract class to a specific implementation in Dagger when the implementation already exists in the dependency graph. It generates more efficient code than @Provides because it does not require creating a separate instance of the object.

@Provides is used to create instances of objects that cannot be provided through singleton or constructor injection. For example, to create an object from multiple other dependencies or to configure a third-party library.

Using @Binds instead of @Provides for simple cases of "interface -> implementation" reduces the generated code and, consequently, results in faster build times.