using JT1078.DotNetty.Core.Enums; using System; using System.Collections.Concurrent; namespace JT1078.DotNetty.Core.Services { public class JT1078AtomicCounterServiceFactory { private readonly ConcurrentDictionary cache; public JT1078AtomicCounterServiceFactory() { cache = new ConcurrentDictionary(); } public JT1078AtomicCounterService Create(JT1078TransportProtocolType type) { if(cache.TryGetValue(type,out var service)) { return service; } else { var serviceNew = new JT1078AtomicCounterService(); cache.TryAdd(type, serviceNew); return serviceNew; } } } }