// // CallbackConfigRepository.cs // // Copyright (c) František Boháček. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System.Collections.Concurrent; using NosSmooth.Comms.Core; namespace NosSmooth.Comms.Inject; /// /// A repository containing configurations for given connection handlers. /// public class CallbackConfigRepository { private readonly ConcurrentDictionary _configs; /// /// Initializes a new instance of the class. /// public CallbackConfigRepository() { _configs = new ConcurrentDictionary(); } /// /// Get config of the given connection, or default. /// /// The connection to get config of. /// A config for the connection. public CallbackConfig GetConfig(ConnectionHandler connection) { return _configs.GetValueOrDefault(connection, new CallbackConfig(false, false)); } /// /// Set config of the given connection. /// /// The connection to set config. /// The config to set. public void SetConfig(ConnectionHandler connection, CallbackConfig config) { _configs.AddOrUpdate(connection, _ => config, (a, b) => config); } }