私はこの登録作業をしようとしています。私は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();
}
}
}
ありがとうございました!とても簡単。私はちょうど私のテストケースでプライベートを持っていた:) –