I saw in a mprss book this recommendation of singleton (partial code attached):
public static Singleton GetSingleton()
{
if (s_value != null)
retur
I'll post this not as a real answer but as an aside: if you're using .NET 4 you really should consider the Lazy
singleton pattern:
http://geekswithblogs.net/BlackRabbitCoder/archive/2010/05/19/c-system.lazylttgt-and-the-singleton-design-pattern.aspx
public class LazySingleton3
{
// static holder for instance, need to use lambda to construct since constructor private
private static readonly Lazy _instance
= new Lazy(() => new LazySingleton3());
// private to prevent direct instantiation.
private LazySingleton3()
{
}
// accessor for instance
public static LazySingleton3 Instance
{
get
{
return _instance.Value;
}
}
}
Thread-safe, easy to read, and obvious: what's not to like?