/// <inheritdoc cref="IMessageToServiceMapper.AddService(Guid, string, INetworkConnector)"/> public void AddService(Guid id, string name, INetworkConnector networkConnector) { if (!ServiceTypeCache.ContainsKey(name)) { _logger.LogError("Service is not added because it has no message types associated with it. "); return; } Type type = ServiceTypeCache[name][0]; if (_messageToServiceMap.ContainsKey(type)) { IServiceConnector serviceConnector = _messageToServiceMap[type]; _serviceMap.TryAdd(id, serviceConnector); serviceConnector.AddService(networkConnector, id); } else { IServiceConnector serviceConnector = new ServiceConnector(networkConnector, name, id); _serviceMap.TryAdd(id, serviceConnector); foreach (Type messageType in ServiceTypeCache[name]) { _messageToServiceMap.TryAdd(messageType, serviceConnector); } _ = Task.Run(() => serviceConnector.StartPublishingAsync(_cancellationTokenSource.Token), _cancellationTokenSource.Token); } }