google-code-export / google-guice

Automatically exported from code.google.com/p/google-guice
Apache License 2.0
2 stars 1 forks source link

[RFE] Allow binding-based private modules #429

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Following a discussion about the possibilites of injecting the injectee's
class to some other modules, I've finally come one satisfying solution, but
that was a lot of (avoidable) pain.

I used private modules to find the right solution with current tools. (See
TypeInjectionUsingPrivateModules.java for the test case)

However, I think this is real bad, because we could possibly do something
better, like automatizing this behavior directly in the binding, with such
a syntax:

BindingModule myModule = new BindingModule() {
  public void configure() {
    bind(new TypeLiteral<Class<?>> {}).toInstance(getBoundType());
  }
};
bind(MyClass.class).in(Singleton).with(myModule);
bind(MySecondClass.class).with(myModule);
bind(MyThirdClass.class).annotatedWith(MyAnnotation.class).toProvider(MyProvider
.class).with(myModule);

BindingModule would:
1. behave like a PrivateModule
2. be able to provide every binding element (interface class,
implementation class, scope, required annotation, etc.) before applying the
configuration.
3. possibly (but not requiring) allow overwriting the bindings in parent
module.

My use case is in this case the possibility for a class to be easily
injected with objects requiring the injectee's class, but the possibilities
of the BindingModule are multiple.

I'll try to create a stub of the implementation and post it here.

Original issue reported on code.google.com by ogregoire on 22 Sep 2009 at 10:34

Attachments:

GoogleCodeExporter commented 9 years ago
Doesn't look like there's much interest in this, and I'm having a hard time 
understanding the goal of the issue (and the patch).  Please reopen if you have 
a need and/or more concrete ideas for this.

Original comment by sberlin on 20 Feb 2011 at 11:04