Click or drag to resize

GenericSingletonProvider class

Provides generic classes as singletons. The main advantage is that the user classes themselves are no longer have to contain static elements and are therefore inheritable in principle.
Inheritance hierarchy
SystemObject
  NetEti.GlobalsGenericSingletonProvider

Namespace: NetEti.Globals
Assembly: NetEti.Global (in NetEti.Global.dll) Version: 1.0.0+ad672dc5430e1683eae7461ce3945c8e9dce1c49
Syntax
public static class GenericSingletonProvider

The GenericSingletonProvider Type exposes the following members.

Methods
 NameDescription of the
Public MethodStatic MemberGetInstanceT Returns the only instance of the desired class. This instance is created beforehand the first time it is called.
Public MethodStatic MemberGetInstanceT(Boolean) Returns the only instance of the desired class. This instance is created beforehand the first time it is called.
Back to the top
Remarks
File: GenericSingletonProvider.cs
Source: josupeit.com/Weblog/Computer Science and Technology/C# and .NET in general/Implementation of the Singleton with minor adjustments from Erik Nagel, NetEti

08.03.2012 Erik Nagel: created
2012-03-08 Erik Nagel: Now not only existing instances are returned, if they have exactly the generic type T, but also if they are of T are derived. This means that within a framework, for example known base classes from unknown but derived classes as singletons can be accessed, even if the base classes derived from the classes must first be instantiated outside the framework.
01.05.2014 Erik Nagel: Call of Global.DynamicIs(instance, typeof(T)) changed to typeof(T).IsAssignableFrom(instance.GetType()).
2016-11-19 Erik Nagel: Check for public constructor deactivated.
See also