Skip to content

Instantly share code, notes, and snippets.

@alistairjevans
Created July 30, 2021 06:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alistairjevans/6cf270a7d87eca69d37a2c538dc9749e to your computer and use it in GitHub Desktop.
Save alistairjevans/6cf270a7d87eca69d37a2c538dc9749e to your computer and use it in GitHub Desktop.
CovariantTestFailure
using Xunit;
namespace Autofac.Test.Features.OpenGenerics
{
public class OpenGenericCovariantTests
{
private interface INotificationHandler<TNotification>
{
}
private interface INotification
{
}
private class MyNotification : INotification
{
}
private class Handler : INotificationHandler<INotification>
{
}
[Fact]
public void CanResolveCovariantOpenGeneric()
{
var builder = new ContainerBuilder();
builder.RegisterType<Handler>().As<INotificationHandler<INotification>>();
var container = builder.Build();
// Nope...
container.Resolve<INotificationHandler<MyNotification>>();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment