public WebSocketMiddleware(RequestDelegate next,
                            IOptions <WebSocketMiddlewareConfig> options,
                            ILogger <WebSocketMiddleware> logger,
                            StateNotifierService notifier)
 {
     _next     = next;
     _config   = options.Value;
     _logger   = logger;
     _notifier = notifier;
     _notifier.WebSocketService = this;
 }
        private readonly object _lock = new Object();         // sync lock

        public TcpListenerService(
            IOptions <TcpListenerServiceConfig> options,
            ILogger <TcpListenerService> logger,
            StateNotifierService notifier,
            JsonDump dump)
        {
            _config   = options.Value;
            _logger   = logger;
            _notifier = notifier;
            _dump     = dump;
            _cancellationTokenSource = new CancellationTokenSource();
            _connections             = new Dictionary <TcpClient, Task>(); // pending connections
            _listener = new TcpListener(IPAddress.Any, _config.Port);
        }