But if you follow a good design pattern you can avoid this problem:
don't bind to concrete implementations!
Instead of:
@Inject MyCollectionImpl<Object> my;
use:
@Inject @My Collection<Object> my;
This way you can't shoot yourself in the foot if there is no binding
to (Collection<Object>, @My).
Yes, this would work. Although, as much as I love interfaces, there are some times when the implementation is so simple that having an interface over it would be an unnecessary abstraction. Typically, when I do the bindings for those types of dependencies, they are bound to a provider or sometimes a singleton. Either way, the last thing that I want to have happen is for Guice to make me a new one.
We're working on other parts of our process (writing acceptance tests first) so that the development process will give us quick feedback for the times when we've forgotten to specify the bindings. I was just hoping there would be a safety net such that I could disable this automagic binding.
I'm thinking about looking into providing a mechanism for disabling this automatic behavior. If someone knows a good reason why I shouldn't look into this, I'd love to get a heads-up before I invest my time here.
If all you want to do is avoid scoping and provision bypasses by an
implicit binding, you should annotate your implementation class with a
scoping annotation (@Singleton) or a provider indicator:
@ProvidedBy(...).
Then you can tolerate the implicit behavior because your class is
documented with its default scoping and provision use-case and you
never "accidentally" get an alternate instance via nullary ctor.
Dhanji.