public static IRpcHostBuilder AddClientStreamingMethods(this IRpcHostBuilder builder, Type serviceType)
        {
            var serviceName = ((RpcServiceAttribute)serviceType.GetCustomAttribute(typeof(RpcServiceAttribute)))?.Name;

            if (string.IsNullOrWhiteSpace(serviceName))
            {
                serviceName = serviceType.Name;
            }

            foreach (var method in serviceType.GetMethods().Where(_ => _.GetCustomAttribute(typeof(RpcMethodAttribute), true) != null))
            {
                CheckRpcMethodParameterType(method);

                var requestType  = method.GetParameters()[0].ParameterType;
                var responseType = method.ReturnType.GenericTypeArguments[0];

                var handlerGenerator = _unaryHandlerGenerator.MakeGenericMethod(serviceType, requestType, responseType);
                var handler          = handlerGenerator.Invoke(null, new[] { method });

                var methodName = GetMethodName(method);
                var addClientStreamingMethod = _addClientStreamingMethod.MakeGenericMethod(serviceType, requestType, responseType);
                addClientStreamingMethod.Invoke(builder, new[] { handler, serviceName, methodName });
            }

            return(builder);
        }
        public static IRpcHostBuilder UseStartup <TStartup>(this IRpcHostBuilder builder) where TStartup : IStartup
        {
            var startupType         = typeof(TStartup);
            var startupAssemblyName = startupType.FullName;

            return(builder.UseSetting(HostDefaultKey.STARTUPTYPE_KEY, startupAssemblyName).ConfigureServices(services => {
                services.AddSingleton(typeof(IStartup), startupType);
            }));
        }
        public static IRpcHostBuilder UseConfiguration(this IRpcHostBuilder builder, IConfiguration config)
        {
            foreach (var setting in config.AsEnumerable())
            {
                builder.UseSetting(setting.Key, setting.Value);
            }

            return(builder);
        }
        public static IRpcHostBuilder RegisterRpcService(this IRpcHostBuilder builder, List <RpcServiceDescription> rpcServiceDescriptions)
        {
            if (!rpcServiceDescriptions.Any())
            {
                return(builder);
            }

            foreach (var rpcServiceDescription in rpcServiceDescriptions)
            {
                foreach (var rpcMethodDescription in rpcServiceDescription.RpcMethods)
                {
                    var requestType  = rpcMethodDescription.RpcMethod.GetParameters()[0].ParameterType;
                    var responseType = rpcMethodDescription.RpcMethod.ReturnType.GenericTypeArguments[0];

                    switch (rpcMethodDescription.RpcMethodType)
                    {
                    case MethodType.Unary:
                        var unaryHandlerGenerator = _unaryHandlerGenerator.MakeGenericMethod(rpcServiceDescription.RpcServiceType, requestType, responseType);
                        var unaryHandler          = unaryHandlerGenerator.Invoke(null, new[] { rpcMethodDescription.RpcMethod });

                        var addUnaryMethod = _addUnaryMethod.MakeGenericMethod(rpcServiceDescription.RpcServiceType, requestType, responseType);
                        addUnaryMethod.Invoke(builder, new[] { unaryHandler, rpcServiceDescription.RpcServiceName, rpcMethodDescription.RpcMethodName });
                        break;

                    case MethodType.ClientStreaming:
                        // Func<TService, CancellationToken, Task<TResponse>>
                        var clientStreamingHandlerGenerator = _clientStreamingHandlerGenerator.MakeGenericMethod(rpcServiceDescription.RpcServiceType, responseType);
                        var clientStreamingHandler          = clientStreamingHandlerGenerator.Invoke(null, new[] { rpcMethodDescription.RpcMethod });

                        var addClientStreamingMethod = _addClientStreamingMethod.MakeGenericMethod(rpcServiceDescription.RpcServiceType, rpcMethodDescription.RequestDataType, responseType);
                        addClientStreamingMethod.Invoke(builder, new[] { clientStreamingHandler, rpcServiceDescription.RpcServiceName, rpcMethodDescription.RpcMethodName });
                        break;
                    }
                }
            }

            return(builder);
        }
        public static IRpcHostBuilder UseServer(this IRpcHostBuilder builder, string address)
        {
            builder.UseSetting(HostDefaultKey.HOSTADDRESS_KEY, address);

            return(builder);
        }
 public static IRpcHostBuilder UseServer(this IRpcHostBuilder builder, string ip, int port)
 {
     builder.UseServer(string.Format("{0}:{1}", ip, port));
     return(builder);
 }