2 using System.Collections.Concurrent;
3 using System.Collections.Generic;
7 namespace Pithos.Core.Agents
9 static class AgentLocator<T> where T:class
11 static ConcurrentDictionary<string, WeakReference> _agents = new ConcurrentDictionary<string, WeakReference>();
12 public static void Register(T agent,string key)
14 _agents[key] = new WeakReference(agent);
17 public static T Get(string key)
19 return _agents[key].Target as T;
22 public static bool TryGet(string key, out T value)
25 var exists = _agents.TryGetValue(key, out target);
26 value = target.Target as T;
30 public static void Remove(string key)
33 _agents.TryRemove(key, out target);