public static void Register <TInvocator>(this IServiceCollection services, ProxyOptions <TInvocator> options) where TInvocator : IClientWebSocketCommandInvocator
        {
            var invocatorType = typeof(TInvocator);

            services.AddTransient(invocatorType);
            InvocatorFactory.Invocators.Add(invocatorType);
            services.AddSingleton(Options.Create(options));
        }
Example #2
0
        public DefaultClientInvocatorContextFactory(IOptions <ProxyOptions <TInvocator> > options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            _proxyOptions = options.Value;
        }
        public ClientWebSocketConnectorOfInvocator(IServiceProvider serviceProvider,
                                                   IOptions <ProxyOptions <TInvocator> > options,
                                                   IStreamCompressor compressor,
                                                   ILoggerFactory loggerFactory)
            : base(serviceProvider, compressor, loggerFactory)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            Options = options.Value;
        }
Example #4
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="TInvocator"></typeparam>
        /// <param name="connectorName"></param>
        /// <param name="hostAddress">Unique host address</param>
        /// <returns></returns>
        public ProxyWebSocketsBuilder Register <TInvocator>(string connectorName, string hostAddress)
            where TInvocator : IClientWebSocketCommandInvocator
        {
            var invocatorType = typeof(TInvocator);

            InvocatorsHelper.EnsureHostPair(invocatorType, connectorName, hostAddress);

            RegisterInternal <TInvocator>();

            var proxyOptions = new ProxyOptions <TInvocator>
            {
                ConnectorName        = connectorName,
                WebSocketHostAddress = hostAddress
            };

            _services.AddSingleton(Options.Create(proxyOptions));
            _services.AddSingleton <IClientInvocatorContextFactory <TInvocator>, DefaultClientInvocatorContextFactory <TInvocator> >();
            return(this);
        }
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="TInvocator"></typeparam>
        /// <param name="connectorName"></param>
        /// <param name="hostAddress">Unique host address</param>
        /// <returns></returns>
        public ProxyWebSocketsBuilder Register <TInvocator>(string connectorName, string hostAddress)
            where TInvocator : IClientWebSocketCommandInvocator
        {
            var connectorHostPair = new ConnectorHostPair(connectorName, hostAddress, typeof(TInvocator));
            var key = connectorHostPair.Key;

            if (_invocators.TryGetValue(key, out ConnectorHostPair value))
            {
                throw new InvalidOperationException($"\"{connectorName}\" is already registered with same Host and Invocator");
            }

            _invocators.Add(key, connectorHostPair);
            _services.AddSingleton <IWebSocketConnector <TInvocator>, ClientWebSocketConnectorOfInvocator <TInvocator> >();
            var proxyOptions = new ProxyOptions <TInvocator>
            {
                ConnectorName        = connectorName,
                WebSocketHostAddress = hostAddress
            };

            InvocatorRegistryHelper.Register <TInvocator>(_services, proxyOptions);
            return(this);
        }