Microsoft Unity 容器的性能
我正在审查一个使用 Microsoft 模式和实践 Unity 容器的项目。
有一个包含 40 个注册类型的容器,为每个 Web 服务调用创建一个容器实例。
我想知道:
- 注册这么多类型会不会有性能问题?
- Unity 容器可以在 Web 服务调用之间共享吗?
Web 服务托管在 IIS 中。
I am reviewing a project that has used Microsoft Patterns and Practices Unity Container.
There is a single container with 40 registered types, an instance of the container is created for every web service call.
I am wondering:
- Is there a performance problem due to registering so many types?
- Could the unity container be shared between web service calls?
The web services are hosted in IIS.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
第一次完成解析时,Unity 会在后台缓存各种内容。这显着提高了以后解析调用的性能。如果您为每个请求创建一个新容器,您就会丢弃这些缓存。
在请求之间保留容器。
Unity caches all sorts of stuff under the hood the first time a resolve is done. This significantly improves performance on later resolve calls. If you create a new container on every request, you're throwing out those caches.
Keep the container around between requests.
请在Application_Start期间创建容器并注册所有类型。我们已经在一个大型项目(wcf 和 asp.net mvc)中对大约 200 多种类型进行了此操作,并且没有出现任何问题。
谢谢
Please create the container and register all types during Application_Start. We've done this for around 200 + types in a large project (wcf and asp.net mvc) and have had no issues.
Thanks