首页 新闻 搜索 专区 学院

请教一个unity有关于泛型参数的问题

0
悬赏园豆:20 [已解决问题] 解决于 2012-06-25 17:24

<register type="IRepository`1"  mapTo="EdmRepository`1" name="edm"> <lifetime type="singleton" />

</register>

<register type="IPMP_TimeSheet_InfoServices" mapTo="PMP_TimeSheet_InfoServices">

<constructor>

<param name="_Repository">                      

<dependency name="edm"></dependency>                    

</param>                  

</constructor>                         

</register>

 

代码是调用:

IPMP_TimeSheet_InfoServices _IPMP_TimeSheet_InfoServices = myUnityContainer.Resolve<PMP_TimeSheet_InfoServices>();

总是报错:

Resolution of the dependency failed, type = "PSA.Services.PMP_TimeSheet_InfoServices", name = "(none)". Exception occurred while: while resolving. Exception is: InvalidOperationException - The current type, iPSA.Extensions.Repository.IRepository`1[iPSA.SealManagement.DataModel.PMP_TimeSheet_Info], is an interface and cannot be constructed. Are you missing a type mapping? ----------------------------------------------- At the time of the exception, the container was:

  Resolving PSA.Services.PMP_TimeSheet_InfoServices,(none)   Resolving parameter "_Repository" of constructor PSA.Services.PMP_TimeSheet_InfoServices(iPSA.Extensions.Repository.IRepository`1[[iPSA.SealManagement.DataModel.PMP_TimeSheet_Info, DataModel, Version=1.1.1206.8, Culture=neutral, PublicKeyToken=null]] _Repository)     Resolving iPSA.Extensions.Repository.IRepository`1[iPSA.SealManagement.DataModel.PMP_TimeSheet_Info],(none)

那位大哥能帮忙看下,困扰很长时间

hello zly的主页 hello zly | 初学一级 | 园豆:102
提问于:2012-06-21 16:08
< >
分享
最佳答案
1

myUnityContainer.Resolve<PMP_TimeSheet_InfoServices>();

應該改成接口哦

myUnityContainer.Resolve<IPMP_TimeSheet_InfoServices>();

收获园豆:20
無限遐想 | 老鸟四级 |园豆:3740 | 2012-06-22 08:47

我改成了接口还是出错 Resolving PSA.Services.IPMP_TimeSheet_InfoServices,(none)

这是个什么问题

hello zly | 园豆:102 (初学一级) | 2012-06-25 14:06

@hello zly: PMP_TimeSheet_InfoServices 类 。有几个 构造函数。需要的加上一个 dependency属性 看看。

無限遐想 | 园豆:3740 (老鸟四级) | 2012-06-25 14:49

@無限遐想: 已经解决!还是自己不够细心啊!谢谢你的帮助!

hello zly | 园豆:102 (初学一级) | 2012-06-25 17:24
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册