How do I resolve an interface that is implemented by a registered type but is not explicitly registered itself?

Aug 28, 2008 at 3:08 PM
I have the following interfaces:

public interface IView
public interface ISimpleView : IView
public interface IAnotherView : IView

I then register the types with:

container.RegisterType<ISimpleView, SimpleView>();
container.RegisterType<IAnotherView, AnotherView>();

I'd like to get a list of all the IView objects, I've tried the following which just returns an empty collection:

IEnumerable<IView> views = container.ResolveAll<IView>();

Any ideas? Thanks in advance

Aug 28, 2008 at 5:24 PM
You need to explicitly register them as implementing IView. The container doesn't chase up the inheritance hierarchy.

Sep 23, 2008 at 2:20 AM
I am not sure if this what you want to do; but I would do it this way:

container.RegisterType<IView, SimpleView>("SimpleView");
container.RegisterType<IView, AnotherView>("AnotherView");

Then your query will work. However, when you want to use the container to get a type for an interface you will have to provide the name.

I hope this helps.