Skip to content
This repository has been archived by the owner on Dec 19, 2023. It is now read-only.

Contravariant type search doesn't consider decorators for more general variants #54

Closed
LordZoltan opened this issue Sep 21, 2017 · 1 comment
Assignees
Labels

Comments

@LordZoltan
Copy link
Member

LordZoltan commented Sep 21, 2017

Expanding again on the shapes examples in the contravariance documentation, if we reimplement the RectangleComparer as a decorator and register it thus:

container.RegisterDecorator<RectangleComparerDecorator, IComparer<Rectangle>>();

We would expect both the following two assertions to hold:

Assert.IsType<RectangleComparerDecorator>(container.Resolve<IComparer<Rectangle>>());
Assert.IsType<RectangleComparerDecorator>(container.Resolve<IComparer<Square>>()); //fails

Unfortunately, the second fails because the contravariant search for IComparer<Square> doesn't pick up the decorator. It's clearly blind to anything other than a traditional registration.

See this test in the examples project:

[Fact]
public void EmptyDecoratorShouldInjectContravariantBase()

It currently passes because it does partly demonstrate that contravariant decorators do almost work - but the crucial lines within it are commented out:

// BUG #54: this should also work:
//Assert.IsType<RectangleComparerDecorator>(container.Resolve<IComparer<Square>>());

@LordZoltan LordZoltan added the bug label Sep 21, 2017
@LordZoltan LordZoltan self-assigned this Sep 21, 2017
@LordZoltan
Copy link
Member Author

This is actually related to #72

@LordZoltan LordZoltan added this to To do in Rezolver Board Mar 18, 2019
Rezolver Board automation moved this from To do to Done Dec 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
Development

No branches or pull requests

1 participant