Base class for types to restrict instantiation to one object ("singleton pattern").

Namespace: DigitalRune
Assembly: DigitalRune (in DigitalRune.dll) Version: 1.10.0.0 (1.10.0.9503)

Syntax

C#
public abstract class Singleton<T>
where T : new(), Singleton<T>
Visual Basic
Public MustInherit Class Singleton(Of T As {New, Singleton(Of T)})
Visual C++
generic<typename T>
where T : gcnew(), Singleton<T>
public ref class Singleton abstract

Type Parameters

T
The type of the object that is instantiated.

Remarks

Important: In Silverlight the singleton type T needs to be a public type (not a private or internal). This is necessary because of security restrictions in Silverlight.

Thread-Safety: This class is thread-safe. The property Instance can be accessed by multiple threads simultaneously.

Examples

A class can derive from Singleton<(Of <(<'T>)>)> like the class Log in this example:
 Copy imageCopy
public class Log : Singleton<Log>
{
  ...
}
The singleton can be instantiated/accessed by using the property Instance.
 Copy imageCopy
var log = Log.Instance;
var log = Singleton<Log>.Instance;

Inheritance Hierarchy

See Also