1

I'm trying to make this registration work. I have a number of IEventFactory<> responsible for creating different (external) events within my application.

I'd like to resolve all kinds of factories just by it's interface, eg IEventFactory<ClassA>. How do I make my test below succeed?

[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 Answers 2

2

Your interfaces and factories are private. Either make them public/internal or add IncludeNonPublicTypes() in the registration line.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! So simple. I just had them private in my test case :)
1

To add to what @Patrick Steele said, you probably also should be using .WithService.Base()

Have a look at the documentation which details the differences.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.