namespace HermesSocketLibrary.Requests.Callbacks { public class CallbackManager : ICallbackManager where A : class { private readonly IDictionary _callbacks; public CallbackManager() { _callbacks = new Dictionary(); } public string GenerateKeyForCallback(A callback) { string key = GenerateKey(); _callbacks.Add(key, callback); return key; } public A? Get(string key) { if (_callbacks.TryGetValue(key, out var callback)) return callback; return null; } public A? Take(string key) { if (_callbacks.TryGetValue(key, out var callback)) { _callbacks.Remove(key); return callback; } return null; } private string GenerateKey() { return Guid.NewGuid().ToString("D"); } } }