有没有办法在Guice 3.0中声明默认绑定?Guice - 默认绑定定义
这里是我所期待的一个例子:
//Constructor for Class Impl1
@Inject
public Impl1 (@One IMyOwn own)
{
...
}
//Constructor for Class Impl2
@Inject
public Impl2 (@Two IMyOwn own)
{
...
}
//Declare a default binding
bind(IMyOwn.class).to(DefaultMyOwn.class);
//Then, if I want to bind a custom implementation for @Two
bind(IMyOwn.class).annotatedWith(Two.class).to(TwoMyOwn.class);
其实,这个例子不能工作,因为我必须申报所有注释的结合( @一二)。
Guice有解决方案吗? 谢谢。
我必须使用ToConstructorBindings吗? [link](http://code.google.com/p/google-guice/wiki/ToConstructorBindings) – pass1
关于'toConstructor'绑定:这适用于您无法用'@Inject'注释构造函数的情况。既然你可以,这对你来说不是问题。 –