public string GetInvocationHashCode() { string signatureHash = InvocationSignature.GetHashCode().ToString(); string requestIdentifierHash = !string.IsNullOrWhiteSpace(RequestIdentifierKey) ? RequestIdentifierKey.GetHashCode().ToString() : "0"; StringBuilder strBuilder = new StringBuilder(signatureHash); strBuilder.Append($"_{requestIdentifierHash}"); return(strBuilder.ToString()); }
/// <inheritdoc /> protected internal override object Invoke(MethodInvocation invocation) { var targetMethod = MethodCache.GetMethodMap(TargetType, invocation.Method); var signature = new InvocationSignature( invocation.Method, targetMethod, DeclaringType, TargetType, invocation.Method.GetInvocationType()); return(Interceptor.Intercept( signature, invocation.MethodCall, invocation.Arguments, Target, invocation.TransparentProxy)); }
/// <inheritdoc /> public void Intercept(IInvocation invocation) { object Proceed(object target, object[] arguments) { invocation.Proceed(); return(invocation.ReturnValue); } var signature = new InvocationSignature( invocation.Method, invocation.MethodInvocationTarget, typeof(TService), typeof(TImplementation), invocation.Method.GetInvocationType()); invocation.ReturnValue = _invocationInterceptor.Intercept( signature, Proceed, invocation.Arguments, invocation.InvocationTarget, invocation.Proxy); }
/// <inheritdoc /> public IInvocationWeaveDataProvider Create(Type declaredType, Type targetType) { var key = new TypePair(declaredType, targetType); return(_providerCache.GetOrAdd(key, typeKey => { var invocationsData = new ConcurrentDictionary <IInvocationSignature, InvocationWeaveData>( InvocationSignature.InvocationSignatureMethodEqualityComparer.Instance); var declaredMethods = typeKey.DeclaringType.GetMethods() .Union(typeKey.DeclaringType.GetInterfaces() .SelectMany(i => i.GetMethods())); foreach (var declaredMethod in declaredMethods) { var targetMethod = ReflectedMethod.GetMethodMap(typeKey.ImplementationType, declaredMethod); if (targetMethod == null) { throw new IvorySharpException( $"Не удалось найти метод '{declaredMethod.Name}' в типе '{typeKey.ImplementationType.Name}'"); } var signature = new InvocationSignature( declaredMethod, targetMethod, typeKey.DeclaringType, typeKey.ImplementationType, declaredMethod.GetInvocationType()); if (_weavePredicate == null) { _weavePredicate = _weavePredicateHolder.Get(); } var isWeaveable = _weavePredicate.IsWeaveable(signature); if (!isWeaveable) { invocationsData.TryAdd(signature, InvocationWeaveData.Unweavable()); continue; } if (_factory == null) { _factory = _preInitializerHolder.Get(); } var boundaryAspects = _factory.CreateBoundaryAspects(signature); var interceptAspect = _factory.CreateInterceptAspect(signature); if (_pipelineFactory == null) { _pipelineFactory = _pipelineFactoryHolder.Get(); } var pipeline = _pipelineFactory.CreatePipeline(signature, boundaryAspects, interceptAspect); var executor = _pipelineFactory.CreateExecutor(signature); invocationsData.TryAdd(signature, InvocationWeaveData.Weavable(pipeline, executor, boundaryAspects, interceptAspect)); } return new InvocationWeaveDataProvider(invocationsData); })); }