I see strange behavior in a Unity container when working with two interfaces that both register on the same decorator. Sample code will be more understandable.
I have the following class hierarchy:
public interface IBaseInterface { } public interface IInterface1: IBaseInterface { } public interface IInterface2: IBaseInterface { } public class Interface1Impl : IInterface1 { } public class Interface2Impl : IInterface2 { } public class BaseInterfaceDecorator: IInterface1,IInterface2 { private readonly IBaseInterface baseInterface; public BaseInterfaceDecorator(IBaseInterface baseInterface) { this.baseInterface = baseInterface; } } public class MyClass { private readonly IInterface1 interface1; public MyClass(IInterface1 interface1) { this.interface1 = interface1; } }
And this is the registration code:
var container = new UnityContainer(); container.RegisterType<IInterface1, BaseInterfaceDecorator>( new InjectionConstructor( new ResolvedParameter<Interface1Impl>())); container.RegisterType<IInterface2, BaseInterfaceDecorator>( new InjectionConstructor( new ResolvedParameter<Interface2Impl>())); var dependency = container.Resolve<MyClass>();
When resolving MyClass, I get a BaseInterfaceDecorator with interface 2Impl instead of Interface1Impl. Seems strange to me. Can you explain?
c # unity-container
Doron yaacoby
source share