Class Registry<T>
Represents a thread-safe registry of T. This class is efficient for concurrent read access and is
not designed for cases when frequent modifications happen. It is ideal for lookup of named instances
(such as components) that have much longer time span than components that look them up.
Registry performs lock-free lookup which speeds-up many concurrent operations that need to map
names into objects. The enumeration over registry makes a snapshot of its data, hence a registry may
get modified by other threads while being enumerated.
Inheritance
System.Object
Registry<T>
Implements
System.Collections.Generic.IEnumerable<T>
System.Collections.IEnumerable
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Assembly: Azos.dll
Syntax
[Serializable]
public class Registry<T> : IRegistry<T>, IEnumerable<T>, IEnumerable where T : INamed
Type Parameters
Constructors
Registry()
Declaration
Registry(Boolean)
Declaration
public Registry(bool caseSensitive)
Parameters
Type |
Name |
Description |
System.Boolean |
caseSensitive |
|
Registry(IEnumerable<T>)
Declaration
public Registry(IEnumerable<T> other)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
other |
|
Registry(IEnumerable<T>, Boolean)
Declaration
public Registry(IEnumerable<T> other, bool caseSensitive)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<T> |
other |
|
System.Boolean |
caseSensitive |
|
Fields
m_Sync
Declaration
[NonSerialized]
protected object m_Sync
Field Value
Type |
Description |
System.Object |
|
Properties
Count
Returns the number of entries in the registry
Declaration
public int Count { get; }
Property Value
Type |
Description |
System.Int32 |
|
IsCaseSensitive
Returns true if the instance differentiates names by case
Declaration
public bool IsCaseSensitive { get; }
Property Value
Type |
Description |
System.Boolean |
|
Item[String]
Returns a value by name or null if not found
Declaration
public T this[string name] { get; }
Parameters
Type |
Name |
Description |
System.String |
name |
|
Property Value
Names
Declaration
public IEnumerable<string> Names { get; }
Property Value
Type |
Description |
System.Collections.Generic.IEnumerable<System.String> |
|
Values
Declaration
public IEnumerable<T> Values { get; }
Property Value
Type |
Description |
System.Collections.Generic.IEnumerable<T> |
|
Methods
Clear()
Deletes all items from registry
Declaration
public virtual void Clear()
ContainsName(String)
Declaration
public bool ContainsName(string name)
Parameters
Type |
Name |
Description |
System.String |
name |
|
Returns
Type |
Description |
System.Boolean |
|
GetEnumerator()
Declaration
public IEnumerator<T> GetEnumerator()
Returns
Type |
Description |
System.Collections.Generic.IEnumerator<T> |
|
GetOrRegister<TContext>(String, Func<TContext, T>, TContext)
Tries to find an item by name, and returns it if it is found, otherwise calls a factory function supplying context value and registers the obtained
new item. The first lookup is performed in a lock-free way and if an item is found then it is immediately returned.
The second check and factory call operation is performed atomically under the lock to ensure consistency
Declaration
public T GetOrRegister<TContext>(string name, Func<TContext, T> regFactory, TContext context)
Parameters
Type |
Name |
Description |
System.String |
name |
|
System.Func<TContext, T> |
regFactory |
|
TContext |
context |
|
Returns
Type Parameters
Name |
Description |
TContext |
|
GetOrRegister<TContext>(String, Func<TContext, T>, TContext, out Boolean)
Tries to find an item by name, and returns it if it is found, otherwise calls a factory function supplying context value and registers the obtained
new item. The first lookup is performed in a lock-free way and if an item is found then it is immediately returned.
The second check and factory call operation is performed atomically under the lock to ensure consistency
Declaration
public T GetOrRegister<TContext>(string name, Func<TContext, T> regFactory, TContext context, out bool wasAdded)
Parameters
Type |
Name |
Description |
System.String |
name |
|
System.Func<TContext, T> |
regFactory |
|
TContext |
context |
|
System.Boolean |
wasAdded |
|
Returns
Type Parameters
Name |
Description |
TContext |
|
JustRegistered(T)
Declaration
protected virtual void JustRegistered(T item)
Parameters
Type |
Name |
Description |
T |
item |
|
JustReplaced(T, T)
Declaration
protected virtual void JustReplaced(T existingItem, T newItem)
Parameters
Type |
Name |
Description |
T |
existingItem |
|
T |
newItem |
|
JustUnregistered(T)
Declaration
protected virtual void JustUnregistered(T item)
Parameters
Type |
Name |
Description |
T |
item |
|
Register(T)
Registers item and returns true if it was registered, false if this named instance already existed in the list
Declaration
public bool Register(T item)
Parameters
Type |
Name |
Description |
T |
item |
|
Returns
Type |
Description |
System.Boolean |
|
RegisterOrReplace(T)
Registers item and returns true if it was registered, false if this named instance already existed and was replaced
Declaration
public bool RegisterOrReplace(T item)
Parameters
Type |
Name |
Description |
T |
item |
|
Returns
Type |
Description |
System.Boolean |
|
RegisterOrReplace(T, out T)
Registers item and returns true if it was registered, false if this named instance already existed and was replaced
Declaration
public bool RegisterOrReplace(T item, out T existing)
Parameters
Type |
Name |
Description |
T |
item |
|
T |
existing |
|
Returns
Type |
Description |
System.Boolean |
|
TryGetValue(String, out T)
Declaration
public bool TryGetValue(string name, out T value)
Parameters
Type |
Name |
Description |
System.String |
name |
|
T |
value |
|
Returns
Type |
Description |
System.Boolean |
|
Unregister(T)
Unregisters item and returns true if it was unregistered, false if it did not exist
Declaration
public bool Unregister(T item)
Parameters
Type |
Name |
Description |
T |
item |
|
Returns
Type |
Description |
System.Boolean |
|
Unregister(String)
Unregisters item by name and returns true if it was unregistered, false if it did not exist
Declaration
public bool Unregister(string name)
Parameters
Type |
Name |
Description |
System.String |
name |
|
Returns
Type |
Description |
System.Boolean |
|
Explicit Interface Implementations
IEnumerable.GetEnumerator()
Declaration
IEnumerator IEnumerable.GetEnumerator()
Returns
Type |
Description |
System.Collections.IEnumerator |
|
Implements
System.Collections.Generic.IEnumerable<T>
System.Collections.IEnumerable
Extension Methods