Example #1
0
        public static T Get <T>()
        {
            lock (_instances)
            {
                if (!_instances.TryGetValue(typeof(T), out var obj))
                {
                    SingletonException.Throw <T>($"No instances of singleton {typeof(T)}");
                }

                return((T)obj);
            }
        }
Example #2
0
 public static void Init <T>(this IAutoSingleton <T> singleton)
 {
     lock (_instances)
     {
         if (_instances.ContainsKey(typeof(T)))
         {
             SingletonException.Throw <T>();
         }
         else
         {
             _instances[typeof(T)] = singleton;
         }
     }
 }