I'm trying to register a Generic Interface with multiple Types using Autofac and I like to call:
To resolve all the Implementations of IGenericInterface with a type of IInterface.
I already tried to register the concrete classes that have the generic interface with a concrete class as generic interface with the Interface:
builder.Register(r => new TalkToMeLoud()) .As<IGenericInterface<Hello>>() .As<IGenericInterface<Bye>>() .As<IGenericInterface<IInterface>>() .InstancePerDependency();
But this will throw an error:
An unhandled exception of type 'System.ArgumentException' occurred in Autofac.dll
Additional information: The type 'TestConsoleApp.TalkToMeLoud' is not assignable to service 'TestConsoleApp.IGenericInterface`1[[TestConsoleApp.IInterface, TestConsoleApp, Version=126.96.36.199, Culture=neutral, PublicKeyToken=null]]'.
Because this is part of a migration from Unity to Autofac I know this can be done by Unity like this:
Does anyone know how to solve this problem?
PS: This is my testproject