2012-09-13 28 views
0

我想註冊實現字典適配器的多個組件,但AllTypes.From ..只能選擇類類型。我想要做這樣的事情:castle:按照慣例註冊接口代理

 container.Register(AllTypes.FromAssemblyContaining<IFooSettings>() 
      .Where(type => type.IsInterface) 
      .Configure(component => 
       component.UsingFactoryMethod((kernel, model, creationContext) => new DictionaryAdapterFactory().GetAdapter(creationContext.RequestedType, ConfigurationManager.AppSettings)))); 

現在我不能似乎能夠因爲FromTypesDescriptor構造函數是內部創建自己的「AllTypes」的版本。任何想法我可以做到這一點?

回答

0

這現在在城堡3.3.0:

var dictionaryAdapterFactory = new DictionaryAdapterFactory(); 

container.Register(
     Types.FromThisAssembly().Where(t => t.Name.EndsWith("Settings") && t.IsInterface) 
      .Configure(component => component.UsingFactoryMethod((kernel, model, creationContext) => dictionaryAdapterFactory.GetAdapter(creationContext.RequestedType, ConfigurationManager.AppSettings)))); 

您必須使用「類型」,這也拿起接口

0

我做這樣的事情

container.Register(
     AllTypes 
      .FromThisAssembly() 
      .Pick() 
      .WithService.DefaultInterface() 
      .Configure(r => r.LifeStyle.Transient)); 

這將註冊一個基於匹配的接口和類名的組成部分。

因此,如果我要求城堡爲一個名爲IFooSettings的界面,那麼城堡默認會返回類FooSettings

有一系列規則可以用於註冊,你可以看到他們here。不建議使用您在示例中使用的Factory方法。

+0

你沒有回答這個問題。閱讀標題,我想註冊Castle自動創建代理的類型。閱讀DictionaryAdapter。 – Marius

相關問題