Files
Umbraco-CMS/src/Umbraco.Web/Singleton.cs
shannon@ShandemVaio 9679d0f6df Renamed umbraco.presentation to Umbraco.Web and changed the folder it resides in.
Started removal of files/folder from Umbraco.Web that belong in Umbraco.Web.UI.
2012-07-18 23:54:20 +06:00

50 lines
918 B
C#

using System;
/// <changelog>
/// <item who="Esben" when="17. november 2006">Created</item>
/// </changelog>
namespace umbraco
{
/// <summary>
///
/// Threadsafe Singleton best practice design pattern template
///
/// Sample:
///
/// public class Demo
/// {
/// public static Form1 instance1
/// {
/// get
/// {
/// return Singleton<Form1>.Instance;
/// }
/// }
/// }
/// </summary>
/// <typeparam name="T">Any class that implements default constructor</typeparam>
public sealed class Singleton<T> where T : new()
{
private Singleton()
{
}
public static T Instance
{
get { return Nested.instance; }
}
private class Nested
{
// Explicit static constructor to tell C# compiler
// not to mark type as beforefieldinit
static Nested()
{
}
internal static readonly T instance = new T();
}
}
}