private ServiceHubRemoteHostClient(
            HostWorkspaceServices services,
            IServiceBroker serviceBroker,
            ServiceBrokerClient serviceBrokerClient,
            HubClient hubClient,
            Stream stream,
            IRemoteServiceCallbackDispatcherProvider callbackDispatcherProvider)
        {
            _connectionPools = new ConnectionPools(
                connectionFactory: (serviceName, pool, cancellationToken) => CreateConnectionImplAsync(serviceName, callbackTarget: null, pool, cancellationToken),
                capacity: ConnectionPoolCapacity);

            // use the hub client logger for unexpected exceptions from devenv as well, so we have complete information in the log:
            services.GetService <IWorkspaceTelemetryService>()?.RegisterUnexpectedExceptionLogger(hubClient.Logger);

            _services                            = services;
            _serviceBroker                       = serviceBroker;
            _serviceBrokerClient                 = serviceBrokerClient;
            _hubClient                           = hubClient;
            _callbackDispatcherProvider          = callbackDispatcherProvider;
            _endPoint                            = new RemoteEndPoint(stream, hubClient.Logger, incomingCallTarget: this);
            _endPoint.Disconnected              += OnDisconnected;
            _endPoint.UnexpectedExceptionThrown += OnUnexpectedExceptionThrown;
            _endPoint.StartListening();

            _assetStorage                = services.GetRequiredService <ISolutionAssetStorageProvider>().AssetStorage;
            _serializer                  = services.GetRequiredService <ISerializerService>();
            _errorReportingService       = services.GetService <IErrorReportingService>();
            _shutdownCancellationService = services.GetService <IRemoteHostClientShutdownCancellationService>();
            _isRemoteHostServerGC        = RemoteHostOptions.IsServiceHubProcessServerGC(services);
            _isRemoteHostCoreClr         = RemoteHostOptions.IsServiceHubProcessCoreClr(services);
        }
        private ServiceHubRemoteHostClient(
            HostWorkspaceServices services,
            RemoteProcessConfiguration configuration,
            ServiceBrokerClient serviceBrokerClient,
            HubClient hubClient,
            IRemoteServiceCallbackDispatcherProvider callbackDispatcherProvider)
        {
            // use the hub client logger for unexpected exceptions from devenv as well, so we have complete information in the log:
            services.GetService <IWorkspaceTelemetryService>()?.RegisterUnexpectedExceptionLogger(hubClient.Logger);

            _services                   = services;
            _serviceBrokerClient        = serviceBrokerClient;
            _hubClient                  = hubClient;
            _callbackDispatcherProvider = callbackDispatcherProvider;

            _assetStorage                = services.GetRequiredService <ISolutionAssetStorageProvider>().AssetStorage;
            _errorReportingService       = services.GetService <IErrorReportingService>();
            _shutdownCancellationService = services.GetService <IRemoteHostClientShutdownCancellationService>();
            Configuration                = configuration;
        }
        /// <summary>
        /// This overload is meant to be used by partner teams from their External Access layer.
        /// </summary>
        internal RemoteServiceConnection <T> CreateConnection <T>(ServiceDescriptors descriptors, IRemoteServiceCallbackDispatcherProvider callbackDispatcherProvider, object?callbackTarget) where T : class
        {
            var descriptor         = descriptors.GetServiceDescriptor(typeof(T), Configuration);
            var callbackDispatcher = (descriptor.ClientInterface != null) ? callbackDispatcherProvider.GetDispatcher(typeof(T)) : null;

            return(new BrokeredServiceConnection <T>(
                       descriptor,
                       callbackTarget,
                       callbackDispatcher,
                       _serviceBrokerClient,
                       _assetStorage,
                       _errorReportingService,
                       _shutdownCancellationService));
        }