RegisterType: registering interface with another interface

Oct 6, 2010 at 6:53 AM
  

Is it possible to register one interface with another in Unity, meaning, that we have already registered a type to the "parent" interface, and we want all the child interfaces being registered with the same type?

 

So, I want something like the following:

 

public interface IChild {} 
public interface IParent : IChild {} 
public class ParentClass : IParent {} 
unity.RegisterType<IParent, ParentClass>(); 
unity.RegisterType<IChild, IParent>();
I got errors when trying to resolve IChild in this case. However, if I register IParent with an instance (unity.RegisterInstance<IParent>(new ParentClass())), it works correct. Why it doesn't work with the type registration?
For me it's really the case, because I have many "IChildren" which get registered with the same "ParentClass"
Oct 6, 2010 at 9:37 AM

That is actually by design.  Same discussion as with this thread.

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com