Open GoogleCodeExporter opened 9 years ago
See thread
[http://groups.google.com/group/google-guice/browse_thread/thread/5845897c2f5eee
08]
Original comment by wyue...@gmail.com
on 18 Dec 2007 at 6:45
Original comment by limpbizkit
on 14 May 2008 at 4:27
I changed the issue description from "bind(Impl.class).to(Impl.class) should
work"
to "bind(SomeConcreteType.class).toConstructor() That's how I believe we should
solve
this use case.
Binding a type to itself is misleading, since it suggests that
bind(Foo.class).to(RealFoo.class)
means 'bind Foo to the constructor of RealFoo', whereas it really means 'bind
Foo to
the binding for RealFoo'.
See also issue 231.
Original comment by limpbizkit
on 31 Oct 2008 at 8:31
Implemented over a series of changes:
r1005 adds SPI access
r1022 implements it
r1023, r1024 r1025: tests, tests, tweaks
We may consider implementing "@New" on top of toConstructor() bindings.
One interesting consequence of toConstructor is the impact on scoping. Suppose
you bind the same type
under two different keys:
@Singleton
class A {}
public class BindSomeAsModule extends AbstractModule {
public void configure() {
bind(A.class).annotatedWith(named("1")).toConstructor(A.class.getDeclaredConstructor());
bind(A.class).annotatedWith(named("2")).toConstructor(A.class.getDeclaredConstructor());
}
}
Ultimately, you'll get two instances of A, one for each binding. It seems
awkward until you consider the fact
that the two bindings could be pointing at distinct constructors, in which case
it would be impossible to use a
single instance.
Original comment by limpbizkit
on 21 Jun 2009 at 6:20
I think that is acceptable. having two bind rules that chain toCtor implies
wanting two
separate instances methinks. The ctor is the end point of every bind rule
anyway
(whether implicitly or in this awesome new jessefeature)
Original comment by dha...@gmail.com
on 21 Jun 2009 at 9:46
Original issue reported on code.google.com by
wyue...@gmail.com
on 18 Dec 2007 at 6:42