C# StructureMap参数超出泛型接口的范围
我对以下structuremap配置示例有一个奇怪的问题: IReturnValueC# StructureMap参数超出泛型接口的范围,c#,.net,dependency-injection,structuremap,structuremap3,C#,.net,Dependency Injection,Structuremap,Structuremap3,我对以下structuremap配置示例有一个奇怪的问题: IReturnValue public interface IReturnValue { } public interface IService<T> where T : IReturnValue { void Execute(); } iSeries设备 public interface IReturnValue { } public interface IService<T> w
public interface IReturnValue {
}
public interface IService<T> where T : IReturnValue {
void Execute();
}
iSeries设备
public interface IReturnValue {
}
public interface IService<T> where T : IReturnValue {
void Execute();
}
没有InnerException和其他错误
注册表更改顺序
当我更改注册顺序时,一切正常,我可以使用这些服务
static void Main(string[] args)
{
IContainer container = new Container();
container.Configure(c => c.For<IService<IReturnValue>>().Use<ServiceA>());
container.Configure(c => c.For<ServiceB>().Use<ServiceB>());
}
static void Main(字符串[]args)
{
IContainer容器=新容器();
Configure(c=>c.For().Use());
Configure(c=>c.For().Use());
}
有人能解释为什么structuremap在第一个注册示例中有问题吗
- 结构图:3.0.5.130
- .Net 4.5
ServiceB
?容器甚至可以在不注册类的情况下解析类。是的,这是正确的。但我认为ServiceB的注册也应该是可能的,这个例外对我来说毫无意义。我偶然发现了同样的限制,但对我来说这是一个阻碍。你找到解决办法了吗?
Specified argument was out of the range of valid values.
Parameter name: instance 'Example.ServiceA' with ReturnType
Example.ServiceA cannot be cast to Example.ServiceB
static void Main(string[] args)
{
IContainer container = new Container();
container.Configure(c => c.For<IService<IReturnValue>>().Use<ServiceA>());
container.Configure(c => c.For<ServiceB>().Use<ServiceB>());
}