2011-11-09 5 views
1

私はこの登録作業をしようとしています。私はIEventFactory<>の番号がアプリケーション内で異なる(外部の)イベントを作成する責任があります。Castle Windsorとのインタフェースでオープンジェネリックタイプを登録するには?

私はすべての種類の工場をそのインタフェースで解決したいと考えています(例:IEventFactory<ClassA>)。下のテストを成功させるにはどうしたらいいですか?

[TestFixture] 
public class WindsorTests 
{ 

    [Test] 
    public void Test_factory_registration() 
    {   

     WindsorContainer container = new WindsorContainer(); 
     container.AddFacility<TypedFactoryFacility>(); 

     container.Register(AllTypes.FromThisAssembly().BasedOn(typeof(IEventFactory<>)).WithService.AllInterfaces()); 

     IEventFactory<ClassA> factoryA = container.Resolve<IEventFactory<ClassA>>(); 
     IEventFactory<ClassB> factoryB = container.Resolve<IEventFactory<ClassB>>(); 

    } 


    class ClassA 
    { 

    } 

    class ClassB 
    { 

    } 


    interface IEventFactory<TCaller> 
    { 
     void Foo(); 
    } 


    class EventFactoryA : IEventFactory<ClassA> 
    { 

     public void Foo() 
     { 
      throw new NotImplementedException(); 
     } 
    } 

    class EventFactoryB : IEventFactory<ClassB> 
    { 

     public void Foo() 
     { 
      throw new NotImplementedException(); 
     } 
    } 

} 

答えて

2

あなたのインターフェイスと工場はプライベートです。それらをpublic/internalにするか、登録行にIncludeNonPublicTypes()を追加してください。 @Patrickスティールは、あなたはおそらくも違いを詳細に見てat the documentationをお持ちの.WithService.Base()

を使用しなければならない、言ったことに追加する

+0

ありがとうございました!とても簡単。私はちょうど私のテストケースでプライベートを持っていた:) –

1

関連する問題