C# Unity Factory 应该是单例吗?
我们有一个正在处理各种 XML 消息的应用程序。我们使用依赖注入和单例工厂来创建相关消息的实例。我们使用 WCF 从队列中挑选这些消息,因此当我们启动 WCF 服务时,它会启动多个实例,使我们能够同时处理队列中的消息。
我们使用单例实现了我们的工厂,只是担心我们可能会遇到问题,因为我们正在并行处理多个实例。 (像这样的问题现在是一个瓶颈,可能会遇到线程争用等)
我们不应该让工厂成为单例吗?只是好奇......希望对此有更多专家意见,因为我在这方面一无所知。
任何建议/意见将不胜感激。
谢谢,
S
Possible Duplicate:
Is it better to create a singleton to access unity container or pass it through the application?
We have an application that is processing various XML messages. We are using Dependency Injection along with a Singleton Factory to create instances of the related messages. We are using WCF to pick these messages off of a queue so when we launch the WCF Service it is spinning up multiple instances enabling us to process messages concurrently off of the queue.
We implemented our factory using a Singleton and just concerned we could encounter issues because we are processing multiple instances in parallel. (Issues like this is now a bottleneck, could encounter thread contention, etc)
Should we not make the Factory a Singleton? Just curious....wanted some more expert opinion on this as I am ignorant in this area.
Any suggestions / comments would be greatly appreciated.
thanks,
S
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您使用 DI 时,几乎不需要单例。
相反,我会在 Composition Root 中编写所有内容,并使用适当的生命周期管理Unity 创建相当于 Singleton 的东西。
When you're using DI, Singletons are almost never necessary.
Instead I would compose everything at the Composition Root and use appropriate lifetime management with Unity to create the equivalent of Singletons.