2using System.Collections.Generic;
12 [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, AllowMultiple =
false, Inherited =
true)]
15 private static readonly Dictionary<SingletonKey, SingletonRecord> instances =
new Dictionary<SingletonKey, SingletonRecord>();
26 internal static void Clear()
33 instances.Values.CopyTo(Objects, 0);
37 foreach (SingletonRecord Rec
in Objects)
39 if (Rec.Instantiated && Rec.Instance is IDisposable Disposable)
60 public object Instantiate(
bool ReturnNullIfFail, Type Type, params
object[] Arguments)
70 object Object =
Types.
Create(ReturnNullIfFail, Type, Arguments);
78 if (Object is IDisposable Disposable)
95 public static void Register(
object Object, params
object[] Arguments)
101 if (instances.ContainsKey(Key))
102 throw new InvalidOperationException(
"Singleton already registered.");
114 public static bool Unregister(
object Object, params
object[] Arguments)
120 return instances.Remove(Key);
136 return instances.ContainsKey(Key);
149 instances.Values.CopyTo(Result, 0);
Static class managing the application event log. Applications and services log events on this static ...
static void Exception(Exception Exception, string Object, string Actor, string EventId, EventLevel Level, string Facility, string Module, params KeyValuePair< string, object >[] Tags)
Logs an exception. Event type will be determined by the severity of the exception.
Defines a class or struct as singleton. This means that when instantiated, using Types....
SingletonAttribute()
Defines a class or struct as singleton. This means that when instantiated, using Types....
static bool Unregister(object Object, params object[] Arguments)
Unregisters a singleton instance of a type.
static SingletonRecord[] GetInstances()
Gets available singleton instances.
object Instantiate(bool ReturnNullIfFail, Type Type, params object[] Arguments)
Returns an instance of the type Type .
static bool IsRegistered(Type Type, params object[] Arguments)
Checks if a singleton type (with optional associated arguments) is registered.
static void Register(object Object, params object[] Arguments)
Registers a singleton instance of a type.
Represents a type and a set of arguments, for which an object instance is the single instantiation.
A record of a singleton instance in memory.
Static class that dynamically manages types and interfaces available in the runtime environment.
static object Create(bool ReturnNullIfFail, Type Type, params object[] Arguments)
Returns an instance of the type Type . Creates an instance of a type. If the constructor requires arg...