// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 // Standard Library using System; namespace AWS.GameKit.Common { /// /// Utility class that wraps class T in a singleton pattern. Use Get() to initialize and return an instance of the wrapped class. /// public abstract class Singleton where T : new() { private static Lazy _instance = new Lazy(); /// /// Instantiates a class of type T if it has not already been instantiated, then returns the pointer to that instance. /// /// The instance of class T public static T Get() { return _instance.Value; } /// /// Gets the current initialized state of the held singleton. /// /// To initialize, call Get(). /// True if the instance is initialized. public static bool IsInitialized() { return _instance.IsValueCreated; } } }