0

I have checked all the documentation and knows well that @Binds used for providing interface dependency.But I am bit confused in current example, lets say I have dependency injection for my interface using @Binds in blow code:

interface MyRepository{

}

@Module
abstract class RepositoryModule{

@Binds
abstract fun bindMyRepository(myRepo:MyRepositoryImpl):MyRepository
}

class RegisterUseCase @Inject constructor(private val myRepo:MyRepository)

But the same thing I can also acheive using @Provides

@Module
class RepositoryModule{

@Provides
fun provideMyRepository():MyRepository{

return MyRespositoryImpl()
}
}

We can acheive same goal by using both binds and provides this thing confusing me. Please explain in details so that I can be more clear with my concept about @Binds and @Provides?

Muhammad Zahab
  • 1,049
  • 10
  • 21
  • https://stackoverflow.com/questions/52586940/what-is-the-use-case-for-binds-vs-provides-annotation-in-dagger2 – Steyrix Oct 12 '22 at 11:37

0 Answers0