I'm using dependency injection pattern for my application without any IoC Container. Now I decided to use some IoC Container because my Composition Root consists of thousands lines of code, but I failed to make it work with my classes, which actively use variance. For example the following interface
public interface IQuery<in TIn, out TOut>
{
IReadOnlyCollection<TOut> Get(TIn key);
}
and service
public class FakeRepository : IQuery<object, string>
{
public IReadOnlyCollection<string> Get(object key)
{
return new[] { key.ToString() };
}
}
Pure DI works fine
IQuery<string, object> service = new FakeRepository();
But neither Autofac nor DryIoc can resolve it.
service = autofacContainer.Resolve<IQuery<string, object>>(); // exception
service = dryIocContainer.Resolve<IQuery<string, object>>(); // exception
Do I need some additional setup? Is there any other IoC container that support this? Am I asking too much?
The full code: https://dotnetfiddle.net/vlw17R