4
我使用MVVM光,並建立了如下綁定集合添加到收藏:Ninject注入的元素,當我創建
class TestModule:NinjectModule
{
public override void Load()
{
Bind<ICollection<Element>>().To<Collection<Element>>();
Bind<Element>().ToSelf();
}
}
當我試圖得到一個ICollection的,我得到一個集合的一個元件。我期待一個exmpty集合。
var _kernel = new StandardKernel(new TestModule());
var col = _kernel.Get<ICollection<Element>>();
Console.WriteLine("Count={0}", col.Count); //Write "Count=1", Expect "Count=0"
這是令人生氣的,違反直覺的,完全沒用的!似乎沒有明顯的方式強制Ninject將空集合注入到類型中。我不想要**在集合中的虛擬對象!就像你所說的那樣,Ninject! – 2011-09-27 19:33:14