Skip to content

Binding annotations on providers don't seem to work #103

Description

@davidbyttow

Perhaps I'm missing something, but I noticed binding annotations (including @nAmed) don't work on providers. For example:

public class TestModule extends AbstractModule {

  @Override protected void configure() {}

  @Provides
  @Named("instance")
  TestObject instance() {
    System.out.println("instance");
    return new TestObject();
  }

  @Provides
  @Singleton
  @Named("singleton")
  TestObject singleton() {
    System.out.println("singleton");
    return new TestObject();
  }
}
public classTestResource {

  private final Provider<TestObject> singletonProvider;
  private final Provider<TestObject> instanceProvider;

  @Inject GuiceTestResource(
      @Named("singleton") Provider<TestObject> singletonProvider,
      @Named("instance") Provider<TestObject> instanceProvider) {
    this.singletonProvider = singletonProvider;
    this.instanceProvider = instanceProvider;
  }

  @GET void get() {
    singletonProvider.get();
   instanceProvider.get();
  }
}

// Output:
// instance
// instance

Both providers use the default non-scoped object provider. However, if I make these different types and remove the binding annotations (e..g, TestObject1, TestObject2), then the scopes are honored it works.

Binding annotations should apply to Providers.

Known issue or am I missing something?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions