Unity: Registering the same type for two interfaces

It looks like the last injection instruction for a given "to" type wins. If you grab a copy of Reflector and take a look at the UnityContainer.RegisterType(Type, Type, string, LifetimeManager, InjectionMember[]) implementation, you'll see why.

IMO, this behaviour is a bug. At the very least, InjectedMembers.ConfigureInjectionFor(Type, string, InjectionMember[]) should throw an exception instead of silently replacing the previous injection configuration. However, it really ought to support what you are attempting.


I don't know if it helps. It's most likely too late for you by now. But, this is achievable if you use named registration, i.e. you register each type to be resolved with a different name.

For example:

Container.RegisterType<IInterface1, BaseInterfaceDecorator>("interface1");
Container.RegisterType<IInterface2, BaseInterfaceDecorator>("interface2");