3using System.Threading.Tasks;
13 [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, AllowMultiple =
false, Inherited =
true)]
16 private static readonly Dictionary<SingletonKey, SingletonRecord> instances =
new Dictionary<SingletonKey, SingletonRecord>();
27 internal static async Task Clear()
34 instances.Values.CopyTo(Objects, 0);
38 foreach (SingletonRecord Rec
in Objects)
45 await DisposableAsync.DisposeAsync();
46 else if (Rec.Instance is IDisposable Disposable)
64 public object Instantiate(
bool ReturnNullIfFail, Type Type, params
object[] Arguments)
74 object Object =
Types.
Create(ReturnNullIfFail, Type, Arguments);
88 await DisposableAsync.DisposeAsync();
96 else if (Object is IDisposable Disposable)
113 public static void Register(
object Object, params
object[] Arguments)
119 if (instances.ContainsKey(Key))
120 throw new InvalidOperationException(
"Singleton already registered.");
132 public static bool Unregister(
object Object, params
object[] Arguments)
138 return instances.Remove(Key);
148 public static void Replace(
object Object, params
object[] Arguments)
170 return instances.ContainsKey(Key);
183 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.
static void Replace(object Object, params object[] Arguments)
Replaces a singleton instance of a type.
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...
Interface for asynchronously disposable objects.