Explicitly add binder dependency when binding to Guice provider instance
<p>Say I want to create a general provider that returns the first item in a collection. Something like:</p>

<pre><code>class P extends Provider&lt;T&gt; {
  private final Provider&lt;Collection&lt;T&gt;&gt; provider;

  FirstItemProvider(Provider&lt;Collection&lt;T&gt;&gt; provider) {
    this.provider = provider;
  }

  @Override
  public T get() {
    Collection&lt;T&gt; input = provider.get();
    Iterator&lt;T&gt; iter = input.iterator();
    return iter.hasNext() ? iter.next() : null;
  }
}
</code></pre>

<p>Now I have various such collections with different annotations and I want to add bindings to this provider, BUT, I also want to be able to traverse bindings with using DefaultBindingTargetVisitor and getDependencies().</p>

<p>I've tried something like:</p>

<pre><code>bind(Key.get(type, annotation))
  .toProvider(new P(
     getProvider(
       Key.get(Types.collectionOf(type.getType()), annotation)
     )
  ));
</code></pre>

<p>This works fine in terms of binding, but the traversal doesn't wok as Guice doesn't detect the dependency.</p>

<p>I couldn't figure out any other way to bind to an annotated producer since it doesn't have an annotation on it.</p>

<p>Is there any way to do what I'm trying to do?</p>

<p>Thanks
Yaron</p>