So, the problem:
interface IControl<in T> where T : Base
{
void Execute(T item);
}
class ControlDerived : ICon开发者_如何学编程trol<Derived>
{
public void Execute(Derived item)
{
}
}
class ControlBase : IControl<Base>
{
public void Execute(Base item)
{
}
}
class Derived : Base
{
}
Is it possible to make Windsor work like this:
var ctls = container.ResolveAll<IControl<Derived>>()
ctls.Lenght == 2 ?
So I could get both implementations?
You're lazy :p
I ran the following test and it passes
[Test]
public void ResolveAll_can_resolve_contravariant_components()
{
Container.Register(Component.For<IAmContravariant<Base>>().ImplementedBy<ContravariantBase>(),
Component.For<IAmContravariant<Derived>>().ImplementedBy<ContravariantDerived>());
var all= Container.ResolveAll<IAmContravariant<Derived>>();
Assert.AreEqual(2, all.Length);
}
精彩评论