2009-05-20 14 views
3

こんにちは経由インタフェースの辞書を注入する: -ウィンザー城: - 私は、インターフェースの辞書を注入しようとしていますが、このように城からエラーを取得していた構成

Castle.MicroKernel.SubSystems.Conversion.ConverterException:NOコンバータIFoo

例外を回避するために、Ifooインターフェイスの一覧を含むラッパーを作成し、プロパティを使用してそれを返します。このラッパーは辞書の代わりにコンフィグレーション==>辞書に使用されました

城にはこの回避策を実行する代わりにInterfaceの辞書しかないのですか?

public interface IFoo {} 
public class Foo {} 
public class IfooWrapper { 
    IList<IFoo> container{get;set;} 
} 
+0

、サービスは、キーまたは値はありますか? –

+0

サービスは値 – user110190

答えて

0

私は非常に似たようなことをしなければなりませんでした。しかし、私はそれが他の何よりも設計の欠陥を露呈したと思う。私はあなたのラッパークラスが標準的な作業方法として行ったように、私のアプリケーションをリファクタリングしました。アプリも大幅に簡素化されました。

キャッスルウィンザーモデルに「自分のやり方」を適用しようとするのではなく、「キャッスルウィンザーのやり方」を行うことの問題でした。城ウィンザーの道がどれほど簡単で良かったかを見るのはかなり謙虚でした。

あなたが問題にした解決策ではありませんが、うまくいけばそれはあなたを助けます。

+0

ですが、うまく解決していませんが、私が考えたものです。しかし、私にとって意味をなさないのは、インターフェースのリストが許されていないのに対し、インターフェースのリストは許されないということです。ラッパークラスは設定にノイズを追加するだけです。 – user110190

6

これは(ウィンザー2.0)私のためだけで正常に動作:この辞書で

namespace WindsorTests { 
    public interface IService {}  
    public class Service1 : IService {}  
    public class Service2 : IService {}  
    public class Consumer { 
     private readonly IDictionary<string, IService> services;  
     public IDictionary<string, IService> Services { 
      get { return services; } 
     }  
     public Consumer(IDictionary<string, IService> services) { 
      this.services = services; 
     } 
    }  

    [TestFixture] 
    public class WindsorTests {  
     [Test] 
     public void DictTest() { 
      var container = new WindsorContainer(new XmlInterpreter(new StaticContentResource(@"<castle> 
<components> 
    <component id=""service1"" service=""WindsorTests.IService, MyAssembly"" type=""WindsorTests.Service1, MyAssembly""/> 
    <component id=""service2"" service=""WindsorTests.IService, MyAssembly"" type=""WindsorTests.Service2, MyAssembly""/> 
    <component id=""consumer"" type=""WindsorTests.Consumer, MyAssembly""> 
     <parameters> 
      <services> 
       <dictionary> 
        <entry key=""one"">${service1}</entry> 
        <entry key=""two"">${service2}</entry> 
       </dictionary> 
      </services> 
     </parameters> 
    </component> 
</components> 
</castle>"))); 
      var consumer = container.Resolve<Consumer>(); 
      Assert.AreEqual(2, consumer.Services.Count); 
      Assert.IsInstanceOfType(typeof(Service1), consumer.Services["one"]); 
      Assert.IsInstanceOfType(typeof(Service2), consumer.Services["two"]); 
     } 
    } 
} 
+0

aha、これはwindsor 2.0でこれを修正できました。私は1.0 rc 3を使用しています – user110190

+0

申し訳ありませんが、私はこれがRC3で動作するとは思わない –

関連する問題