axiosengine/axios/Engine/Singleton.cs

30 lines
769 B
C#
Raw Normal View History

2012-03-19 23:57:59 +00:00
using System;
namespace Axios.Engine
{
//http://ralch.wordpress.com/2008/11/22/the-singleton-pattern-how-to-make-it-reusable/
//http://msdn.microsoft.com/en-us/library/ff650316.aspx
public abstract class Singleton<T> where T: new()
{
private static T instance;
private static object syncRoot = new Object();
public static T Instance
{
get
{
if (instance == null)
{
lock (syncRoot)
{
if (instance == null)
instance = new T();
}
}
return instance;
}
}
}
}