using Autofac.Features.Variance;
using System.Collections.Generic;
public interface IQuery<in TIn, out TOut>
IReadOnlyCollection<TOut> Get(TIn key);
public class FakeRepository : IQuery<object, string>
public IReadOnlyCollection<string> Get(object key)
return new[] { key.ToString() };
public static void Main(string[] args)
IQuery<string, object> service;
service = new FakeRepository();
Console.WriteLine("Poor man's IoC: {0}", string.Join(",", service.Get("42")));
var autofacBuilder = new Autofac.ContainerBuilder();
autofacBuilder.RegisterSource(new ContravariantRegistrationSource());
autofacBuilder.RegisterAssemblyTypes(typeof(FakeRepository).Assembly).AsImplementedInterfaces();
service = autofacBuilder.Build().Resolve<IQuery<string, object>>();
Console.WriteLine("Autofac: {0}", string.Join(",", service.Get("42")));
var dryIocContainer = new DryIoc.Container();
dryIocContainer.RegisterMany(new[] { typeof(FakeRepository).Assembly });
var service1 = dryIocContainer.Resolve<IQuery<string, object>>();
Console.WriteLine("DryIoc: {0}", string.Join(",", service1.Get("42")));