Not currently for simplicity's sake. Did look at a...
# kotlin-inject
e
Not currently for simplicity's sake. Did look at a bit but haven't found a way that has enough benefits to be worth saving just a line of code. If you are binding an impl to an interface the it's probably because you want to be using different impls in different places so you need to tie it to something, it can't just be global. Putting it in a component is a natural way to do that as you can have different components provide different impls for the same interface. Sure you could reverse it and do something like
Copy code
@Binds(in = AppComponent::class)
@Inject
class MyImpl : Impl
but it just feels like shuffling things around? It's also nice to have them all in one place so you can override them all for tests (a common usecase for having multiple impls for an interface).
m
Hi, just want to share my use case regarding this.
If you are binding an impl to an interface the it's probably because you want to be using different impls in different places
Almost all classes in my project are single implementation interfaces. I'm using this pattern to create fakes easily in unit tests. In my current Android project, I use Anvil to solve this issue.
e
I'm using this pattern to create fakes easily in unit tests
So you do have multiple implementations, the real one and the fake 😉 You can totally use kotlin-inject in your tests to set things up passing in the fake as I describe here. Though it's understandable if you want to do manual di in tests instead.