带有泛型的 Unity XML 配置
对于 Unity XML 配置和泛型有点头疼。我有这些文件:
public interface IRepository<T> {}
public class OrderRepository : IRepository { }
public class DispatchOrderProcess
{
public DispatchOrderProcess(IRepository<Order> repository) { }
}
我想使用 Unity XML 配置将 Order Repository 注入到 DispatchOrderProcess 类中。到目前为止我有这样的事情:
<type name="OrderRespository" type="Company.Project.Core.Interfaces.IRepository`1, Company.Project.Core" mapTo="Company.Project.Core.Repositories.OrderRepository, Company.Project.Core" />
<type name="DispatchOrderProccess" type="Company.Project.Core.Interfaces.ISendAlertsProcess, Company.Project.Core" mapTo="Company.Project.Core.Processes.SendAlertsProcess, Company.Project.Core">
<typeConfig>
<constructor>
<param name="orderRepository" parameterType="Company.Project.Core.Interfaces.IRepository`1, Company.Project.Core">
<dependency name="OrderRespository"/>
</param>
</constructor>
</typeConfig>
</type>
</types>
</container>
</containers>
Having a bit of a headache with Unity XML configuration and generics. I have these files:
public interface IRepository<T> {}
public class OrderRepository : IRepository { }
public class DispatchOrderProcess
{
public DispatchOrderProcess(IRepository<Order> repository) { }
}
I would like to inject the Order Repository into the DispatchOrderProcess class using Unity XML configuration. So far I have something like so:
<type name="OrderRespository" type="Company.Project.Core.Interfaces.IRepository`1, Company.Project.Core" mapTo="Company.Project.Core.Repositories.OrderRepository, Company.Project.Core" />
<type name="DispatchOrderProccess" type="Company.Project.Core.Interfaces.ISendAlertsProcess, Company.Project.Core" mapTo="Company.Project.Core.Processes.SendAlertsProcess, Company.Project.Core">
<typeConfig>
<constructor>
<param name="orderRepository" parameterType="Company.Project.Core.Interfaces.IRepository`1, Company.Project.Core">
<dependency name="OrderRespository"/>
</param>
</constructor>
</typeConfig>
</type>
</types>
</container>
</containers>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
...你的问题是?
我最近用泛型做了一些事情,但在语法上遇到了一些问题。显然我需要告诉 Unity T 的类型是什么,比如:
这对你有什么帮助吗?
...and your problem is?
I have done some stuff with generics quite recently though and I had some trouble with the syntax. Apparently I neaded to tell unity what the typeof T was, something like:
does this help you out in any way?