1

Given:

public interface IFeedOperations : IOperationsWithPreInstalledData
{
    ...
}

public class FeedOperations : IFeedOperations
{
}

How do I use RegisterType for a class that implements IFeedOperations AND therefore the IOperationsWithPreInstalledData as well?

public class FeedsInstaller : IDependencyInstaller
{
    public void Install(IDependencyContainer container)
    {
        container.RegisterType(typeof(IFeedOperations), typeof(FeedOperations));
        container.RegisterType(typeof(IOperationsWithPreInstalledData), typeof(FeedOperations));
    }
}

The current code yields the following error. And if I remove the second RegisterType then I get no results when I call container.ResolveAll<IOperationsWithPreInstalledData>().

Component ...Feeds.FeedOperations could not be registered. There is already a component with that name. Did you want to modify the existing component instead? If not, make sure you specify a unique name.

And if I remove the second RegisterType then I get no results when I call container.ResolveAll<IOperationsWithPreInstalledData>(). Castle Windsor doesn't seem to see that a class implementing IFeedOperations also implements IOperationsWithPreInstalledData.

How can I register my implementing class with Castle Windsor so that it knows my class implements both interfaces -- or rather that either interface can be resolved by my class.

6
  • Do you care if two instances of your class will be created (one for each interface)? Commented Jan 20, 2013 at 19:54
  • Would prefer just one instance but I'm not picky in this case. Commented Jan 20, 2013 at 19:55
  • Also, IDependencyContainer doesn't seem to be any type from Castle. Is that your custom interface? Commented Jan 20, 2013 at 19:59
  • yes, that's our type -- we support multiple DI containers. Commented Jan 20, 2013 at 20:11
  • So, are you asking how to use your own code? I'm afraid we can't help you with that. Commented Jan 20, 2013 at 20:12

1 Answer 1

5
container.Register(Component.For<IFoo,IBar>().ImplementedBy<FooBar>());
Sign up to request clarification or add additional context in comments.

2 Comments

Yes, this is what I did to get it working -- figured it out on my own but happy to give you the credit for the answer. Thank you for responding!
is it the same as writing For<IFoo>().Forward<IBar>()?

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.