Table of Contents

Class Singleton<T>

Namespace
VpnHood.Net.Toolkit.Utils
Assembly
VpnHood.Net.Toolkit.dll

Provides a base for a class with one registered instance in the process, which Instance gives.

public class Singleton<T> where T : Singleton<T>

Type Parameters

T

The class itself.

Inheritance
Singleton<T>
Derived
Inherited Members

Constructors

Singleton(bool)

Initializes a new instance of the class and registers it.

protected Singleton(bool register = true)

Parameters

register bool

true to register the instance; false for an ordinary one, as tests run many in one process, which leaves Instance as it is.

Exceptions

InvalidOperationException

An instance is registered already.

Properties

Instance

Gets the registered instance.

public static T Instance { get; }

Property Value

T

Exceptions

InvalidOperationException

No instance is registered.

IsInit

Gets a value indicating whether an instance is registered.

public static bool IsInit { get; }

Property Value

bool

Methods

Dispose()

Disposes the instance, and unregisters it when it is the registered one.

public void Dispose()

Dispose(bool)

Releases the instance; with disposing and when it is the registered one, unregisters it.

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

true when called from Dispose().