public ClientActionExecutingContext(Guid clientProxyId,
                                     IServiceProvider serviceProvider,
                                     string?optionsName,
                                     IOnceCall onceCall,
                                     InstanceMethod instanceMethod,
                                     Func <object?, Task>?callback,
                                     CancellationToken token,
                                     ContractInfo contract,
                                     ContractMethod contractMethod,
                                     ReadStream?stream,
                                     Dictionary <string, object?> header,
                                     object?[] pureArgs)
 {
     ClientProxyId     = clientProxyId;
     StartTime         = DateTimeOffset.Now;
     ServiceProvider   = serviceProvider;
     OnceCall          = onceCall;
     InstanceMethod    = instanceMethod;
     Callback          = callback;
     Contract          = contract;
     ContractMethod    = contractMethod;
     CancellationToken = token;
     Stream            = stream;
     PureArgs          = pureArgs;
     OptionsName       = optionsName;
     Header            = header;
 }
 public ActionExecutingContext(IServiceProvider serviceProvider,
                               Dictionary <string, object?> header,
                               Instance instance,
                               MethodInfo instanceMethodInfo,
                               ContractMethod contractMethod,
                               object?[] args,
                               object?[] pureArgs,
                               ActionInfo actionInfo,
                               ProxyStream?stream,
                               ContractInfo contract,
                               ChannelType channelType,
                               Func <object?, Task>?callback,
                               CancellationToken token)
 {
     Properties        = new Dictionary <object, object?>();
     StartTime         = DateTimeOffset.Now;
     ServiceProvider   = serviceProvider;
     ChannelType       = channelType;
     Header            = header;
     InstanceMethod    = instance.Methods.Find(i => i.MethodInfo == instanceMethodInfo) !;
     ContractMethod    = contractMethod;
     Instance          = instance;
     Args              = args;
     PureArgs          = pureArgs;
     CallbackType      = GetFuncType(args);
     ActionInfo        = actionInfo;
     Callback          = callback;
     Stream            = stream;
     Contract          = contract;
     CancellationToken = token;
     ResetProps();
 }
示例#3
0
文件: Instance.cs 项目: ErgEnn/NetRpc
 public Instance(ContractInfo contract, object target)
 {
     Contract = contract;
     Target   = target;
     Type     = target.GetType();
     foreach (var m in Type.GetMethods())
     {
         Methods.Add(new InstanceMethod(m, target));
     }
 }
示例#4
0
        public static ContractInfo GetOrAdd <T>()
        {
            var type = typeof(T);

            lock (LockObj)
            {
                if (Dic.TryGetValue(type, out var value))
                {
                    return(value);
                }
                var newInfo = new ContractInfo(type);
                Dic.Add(type, newInfo);
                return(newInfo);
            }
        }
示例#5
0
        public Call(Guid clientProxyId, IServiceProvider serviceProvider, ContractInfo contract, IOnceCallFactory factory, int timeoutInterval, string optionsName)
        {
            _clientProxyId   = clientProxyId;
            _serviceProvider = serviceProvider;
            _contract        = contract;
            _factory         = factory;
            _timeoutInterval = timeoutInterval;
            _optionsName     = optionsName;

            if (serviceProvider != null)
            {
                var middlewareOptions = _serviceProvider.GetService <IOptions <ClientMiddlewareOptions> >().Value;
                _middlewareBuilder = new ClientMiddlewareBuilder(middlewareOptions, serviceProvider);
            }
        }
示例#6
0
文件: Call.cs 项目: ErgEnn/NetRpc
 public Call(Guid clientProxyId,
             ContractInfo contractInfo,
             IServiceProvider serviceProvider,
             ClientMiddlewareOptions middlewareOptions,
             IActionExecutingContextAccessor actionExecutingContextAccessor,
             IOnceCallFactory factory,
             int timeoutInterval,
             bool forwardHeader,
             string?optionsName)
 {
     _clientProxyId   = clientProxyId;
     _serviceProvider = serviceProvider;
     _actionExecutingContextAccessor = actionExecutingContextAccessor;
     _contract          = contractInfo;
     _factory           = factory;
     _timeoutInterval   = timeoutInterval;
     _forwardHeader     = forwardHeader;
     _optionsName       = optionsName;
     _middlewareBuilder = new ClientMiddlewareBuilder(middlewareOptions, serviceProvider);
 }
示例#7
0
        private static (MethodInfo instanceMethodInfo, ContractMethod contractMethod) GetMethodInfo(ActionInfo action, ContractInfo contract, object instance)
        {
            var methodObj = contract.Methods.FirstOrDefault(i => i.MethodInfo.ToFullMethodName() == action.FullName);

            if (methodObj != null)
            {
                var instanceMethodInfo = instance.GetType().GetMethod(methodObj.MethodInfo.Name) !;
                if (action.GenericArguments.Length > 0)
                {
                    var ts = action.GenericArguments.ToList().ConvertAll(Type.GetType).ToArray();
                    // ReSharper disable once PossibleNullReferenceException
                    instanceMethodInfo = instanceMethodInfo.MakeGenericMethod(ts !);
                }

                return(instanceMethodInfo, methodObj);
            }

            return(default);
示例#8
0
 public Contract(Type contractType, Func <IServiceProvider, object> instanceFactory)
 {
     _instanceFactory = instanceFactory;
     ContractInfo     = new ContractInfo(contractType);
 }
示例#9
0
 public Contract(Type contractType, Type instanceType)
 {
     InstanceType = instanceType;
     ContractInfo = new ContractInfo(contractType);
 }