以最少的配置使用 Unity
在工作中,我们经常使用Unity。它的工作非常出色,但是您使用它的次数越多,您的配置文件就会增长得越多,运行时问题也会增加得越多,并且您必须为每个测试项目重新创建统一配置的次数就越多。
因此,我们最终得到了一个巨大的统一配置部分,必须在多个项目中复制它,并且当需要部署时,您最终必须追踪您忘记添加引用的 dll,但您只能在运行时发现它们。不好玩。
我猜有人遇到过这个问题并有解决方案。理想情况下,我想弄清楚如何以一种利用约定优于配置并减少运行时问题(即巨大的配置文件)的方式来配置 Unity。有人知道以最少的配置实现 Unity 的好方法吗?
编辑:一件事:我必须坚持只使用 Unity。无法真正切换到 Ninject 等。
At work, we use Unity a lot. It's great at it's job, but the more you use it, the more your configuration file grows, the more runtime issues increase and the more you have to recreate your unity configuration for each test project.
So we end up with a huge unity configuration section that has to be duplicated accross several projects and when it comes time to deploy, you end up having to track down dlls that you forgot to add references to, but you only discover these at runtime. Not fun.
I'm guessing someone has come across this issue and has a solution. Ideally, I would like to figure out how to configure Unity in a way that makes use of convention over configuration and reduces runtime issues (ie, huge configuration files). Anyone know of a good way to implement Unity with minimal configuration?
Edit: One thing: I have to stick with only using Unity. Can't really switch to Ninject, etc.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Unity 有一个配置 API,因此使用反射编写一些自动配置代码非常容易。
有几个人在这里写了博客:
http:// /geekswithblogs.net/watsonjon/archive/2009/09/28/unity-convention-based-registration.aspx
http://geekswithblogs.net/brians/archive/2010/07/04/convention-based -registration-extension-for-the-microsoft-unity-ioc-container.aspx
将此包含在一些您可以重用的框架代码中:
http://thedersen.com/2011/02/20/convention-based-configuration-for-microsoft-unity/
此问题已在 Unity 讨论区 上进行了讨论。问题是每个人都想要不同的约定。看看博客文章,自己写一篇似乎很简单。
Unity has a configuration API so it's pretty easy to write some auto-configuration code using reflection.
Several people have blogged about it here:
http://geekswithblogs.net/watsonjon/archive/2009/09/28/unity-convention-based-registration.aspx
http://geekswithblogs.net/brians/archive/2010/07/04/convention-based-registration-extension-for-the-microsoft-unity-ioc-container.aspx
Including this one with some framework code you can reuse:
http://thedersen.com/2011/02/20/convention-based-configuration-for-microsoft-unity/
This has been discussed on the Unity discussion board. The issue is that everyone wants different conventions. Look at the blog posts, writing your own seems pretty trivial.
在 unity 3.0 中,您现在可以按照约定进行配置。这篇博客文章更详细地解释了它:
http://blogs.msdn.com/b/agile/archive/2013/03/12/unity-configuration-registration-by-convention.aspx
In unity 3.0 you can now do configuration by convention. This blog post explains it in more detail:
http://blogs.msdn.com/b/agile/archive/2013/03/12/unity-configuration-registration-by-convention.aspx