2009-08-28 162 views
0

我有財產以後這樣winsdor註冊一個泛型類型構造函數的參數

MyRepository<T> : IRepository<T> { 

    public MyRepository(string cs){ 
    .... 

}

,所以我需要在winsdor註冊這個泛型類型,並給他一個參數

我一直在嘗試這樣做:

Type t = typeof(IRepository<>); 
Type t1 = typeof(Repository<>); 
Hashtable props = new Hashtable(); 
props.Add("cs", "myconnstring"); 
container.AddComponentWithProperties("key1", t, t1, props); 

我得到以下錯誤

無法創建組件'key1',因爲它具有要滿足的依賴關係。 KEY1正在等待以下相關:

鍵(與特定的鍵組件) - 其中未註冊CS。有關更多信息,

container.Register(Component.For(typeof(IRepository<>)) 
    .ImplementedBy(typeof(MyRepository<>)) 
    .Parameters(Parameter.ForKey("cs").Eq("myconnstring")); 

時退房fluent registration wiki

回答

3

試試這個。

+0

thnx man它工作得很好,我只是把cs的值放在Eq(value) – Omu 2009-09-01 07:01:10

相關問題