统一和泛型
如何在 Unity 中注册并解析通用对象/接口?我试图远离配置文件。
我正在寻找类似
IEnterpriseClient
的内容来解析为 EnterpriseClient
类签名是
class EnterpriseClient<T> : IEnterpriseClient<T> where T : class
谢谢!
how do i register and resolve a generic object/interface in Unity? I'm trying to stay away from the config file.
I'm looking for something like
IEnterpriseClient<IInterface1>
to resolve to EnterpriseClient<IInterface1>
The class signature is
class EnterpriseClient<T> : IEnterpriseClient<T> where T : class
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这几乎正是您所想的:
那就是如果您只想注册特定的封闭泛型。对于开放通用(不仅仅是 IInterface1),您可以这样做:
您提到您已经尝试过这个 - 什么不起作用?
It's pretty much exactly what you'd think:
That's if you only want that particular closed generic registered. For the open generic (not just IInterface1), you can do:
You mentioned you'd tried this - what's not working?
查看此问题以了解 XML 配置:Unity 2.0 通过 XML 注册泛型类型< /a>
和 http://davidhayden.com/blog/ dave/archive/2008/03/25/UnityDependencyInjectionOpenGenericTypes.aspx 用于代码配置。
Look at this question for XML configuration: Unity 2.0 registering generic types via XML
and http://davidhayden.com/blog/dave/archive/2008/03/25/UnityDependencyInjectionOpenGenericTypes.aspx for code configuration.