2010-07-21 35 views
2

我並執行以下操作:溫莎城堡解決字典<>失敗

container.Register(Component.For<Dictionary<string, string>>() 
          .Instance(ServiceDictionaryInstance) 
          .Named("serviceDictionary")); 

類消耗的組分是:

public class BusinessService : IDecisionFilter 
{ 
    private readonly Dictionary<string, string> _ServiceDictionary; 

    public BusinessService(IOtherInterface otherService, Dictionary<string, string> serviceDictionary) 
    { 
        _OtherService = otherService, 
     _ServiceDictionary = serviceDictionary; 
    } 
    } 

然後城堡無法解決字典組件:

失敗:NotImplementedException 該方法或操作未實現。 失敗:在Castle.MicroKernel.SubSystems.Conversion.GenericDictionaryConverter.PerformConversion(字符串值,類型TARGETTYPE)

但如果我創建另一個類:

public class DictiornayType : Dictionary<string, string> 
{ 
} 

代替原來詞典,一切都正確解析。

這與泛型有什麼關係?

請指教。

+0

字典有什麼? BusinessService如何處理它? – 2010-07-22 00:20:50

回答

3

事情是,字典不是真的component/service。這是一些組件/服務的參數。所以,你可以只是刪除詞典登錄並通過字典實例作爲參數,以在其登記的BusinessService組件:

container.Register(Component.For<IDecisionFilter>() 
          .ImplementedBy<BusinessService>() 
          .DependsOn(new { 
           serviceDictionary = ServiceDictionaryInstance 
          })); 

有溫莎的未來版本中有的談removing this difference between parameters and services