有沒有辦法在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'註釋構造函數的情況。既然你可以,這對你來說不是問題。 –