我发现如何使用下面的代码在运行时解析通用接口.如何IGenericInterface<>
在运行时解析所有返回集合的实例.我知道在autofac我们应该使用IEnumerable<T>
但我不知道如何在下面的例子中表示:
var typeInRuntime = typeof (SubClass1);
var instance1 = container.Resolve(typeof(IGenericInterface<>)
.MakeGenericType(typeInRuntime));
Run Code Online (Sandbox Code Playgroud)
这显然不起作用
var typeInRuntime = typeof (SubClass1);
var collection = container
.Resolve(IEnumerable<typeof(IGenericInterface<>)
.MakeGenericType(typeInRuntime)>);
Run Code Online (Sandbox Code Playgroud)