Skip to content

Using a provider implicitly bound in a child private module is not floated to the parent or exposed. #175

Description

@GoogleCodeExporter
What steps will reproduce the problem?
1. Example:
public class FooModule extends PrivateGinModule {
  protected configure() {
    bind(Foo.class).to(FooImpl.class).in(Singleton.class);
    bind(Baz.class);
    expose(Foo.class);
  }
}

// bound in FooModule
public class Baz {
  public Baz(Provider<Foo> fooProvider) {}
}

// Bound in a parent module.
public class Bar {
  public Bar(Provider<Foo> fooProvider) {}
}

What is the expected output?
Gin should recognize that the provider provides a class that is the same as one 
exposed in the child module, and that the rebind should not conflict. The 
provider should be floated to the parent. Alternatively it should expose the 
provider automatically from the child module.

What do you see instead?
Error injecting com.google.inject.Provider<com.example.Foo>: Already bound in 
child Ginjector com.example.FooModule. Consider exposing it? Path to required 
node:  com.example.Bar [com.example.ClientGinjector#getAppController()] -> 
com.google.inject.Provider<com.example.Foo> [@Inject constructor of 
com.example.AppController] 

Please provide any additional information below.

A workaround is to explicitly bind and expose the provider in the private 
module, which is not ideal.
eg.
public class FooModule extends PrivateGinModule {
  protected configure() {
    bind(Foo.class).to(FooImpl.class).in(Singleton.class);
    bind(new TypeLiteral<Provider<Foo>>() {});
    expose(Foo.class);
    expose(new TypeLiteral<Provider<Foo>>() {});
  }
}

Original issue reported on code.google.com by r...@google.com on 21 Mar 2012 at 11:19

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions