Interface IApplicationSingletonManager
Provides singleton instance management (get/set/remove) functionality.
The implementor gets allocated once per application context. All methods are thread-safe.
Singleton instances are keyed on their type - this is designed on purpose as components should not
create global ad hoc object instances (see remarks). The manager disposes all singleton instances on
its own dispose, to bypass this behavior remove all items yourself prior to disposing ApplicationSingletonManager itself
Inherited Members
System.Collections.Generic.IEnumerable<System.Object>.GetEnumerator()
Assembly: Azos.dll
Syntax
public interface IApplicationSingletonManager : IEnumerable<object>, IEnumerable
Methods
Get<T>()
Tries to get a singleton instance or null if it does not exist
Declaration
T Get<T>()
where T : class
Returns
Type Parameters
GetOrCreate<T>(Func<T>)
Tries to get a singleton instance if it exists, if does not then calls a factory and
sets under thread-safe lock. Returns a tuple of (T, bool) later set to true if factory was invoked.
If factory call returns null, the whole Create is canceled (as-if only Get() was called)
Declaration
(T instance, bool created)GetOrCreate<T>(Func<T> factory)
where T : class
Parameters
Type |
Name |
Description |
System.Func<T> |
factory |
|
Returns
Type |
Description |
System.ValueTuple<T, System.Boolean> |
|
Type Parameters
Remove<T>()
Tries to remove instance for the specified type. Returns true if found and removed.
Does NOT call the .Dispose() on the IDisposable instances
Declaration
bool Remove<T>()
where T : class
Returns
Type |
Description |
System.Boolean |
|
Type Parameters
Extension Methods