using Serilog; namespace CommonSocketLibrary.Abstract { public abstract class HandlerTypeManager { private readonly IDictionary _types; public IDictionary HandlerTypes { get => _types; } protected readonly ILogger _logger; public HandlerTypeManager(ILogger logger, HandlerManager handlers) { _types = new Dictionary(); _logger = logger; GenerateHandlerTypes(handlers.Handlers); } private void GenerateHandlerTypes(IDictionary handlers) { foreach (var entry in handlers) { if (entry.Value == null) { _logger.Error($"Failed to link websocket handler #{entry.Key} due to null value."); continue; } var type = entry.Value.GetType(); var target = FetchMessageType(type); if (target == null) { _logger.Error($"Failed to link websocket handler #{entry.Key} due to no match for {target}."); continue; } _types.Add(entry.Key, target); _logger.Debug($"Linked websocket handler #{entry.Key} to type {target.AssemblyQualifiedName}."); } } protected abstract Type? FetchMessageType(Type handlerType); } }