【发布时间】:2015-08-20 10:08:51
【问题描述】:
我正在尝试从文件 Unity.config 加载 Unity 配置。 在接口的实现中使用了泛型参数
我的配置文件:
<?xml version="1.0" encoding="utf-8" ?>
<unity xmlns="http://schemas.microsoft.com/practices/2010/unity">
<assembly name="TestUnity" />
<namespace name="TestUnity" />
<container>
<register type="IGeneric1`2[IGeneric2`1[long], long]" mapTo="ExampleGeneric`2[IGeneric2`1[long], long]">
</register>
</container>
</unity>
程序代码:
public interface IGeneric1<E, in Key> where E : IGeneric2<Key>
{
void Publish(E msg);
}
public interface IGeneric2<out Key>
{
Key SourceId { get; }
}
公共类 ExampleGeneric : IGeneric1 其中 E : IGeneric2 { 公共无效发布(E msg) { 抛出新的 NotImplementedException(); } }
主要:
static void Main(string[] args)
{
IUnityContainer container = new UnityContainer().LoadConfiguration();
}
排队
IUnityContainer container = new UnityContainer().LoadConfiguration();
显示错误:
GenericArguments[0] "TestUnity.IGeneric2`1[Key]", in "TestUnity.IGeneric1`2[E,Key]" violates the constraint of type paremeter "E"
【问题讨论】:
标签: c# unity-container config