c#

Possible Duplicate:
What is so bad about Singletons?
Singleton Design Pattern: Pitfalls

I hear a lot of this but din't find firm reason for it.

Avoid the singleton anti-pattern and replace it with DI.

but, why?


Stateful singletons are much more difficult to unit test.

I use stateless singletons which I don't see a problem with.

Since singletons can implement interfaces, they can be passed using dependency injection (and should be passed as such where possible)

链接地址: http://www.djcxy.com/p/82160.html

上一篇: 为什么使用全局变量类(单例)不好的做法?

下一篇: C#