/// <summary> /// Gets the interceptors that should be invoked for the specified request. /// </summary> /// <param name="request">The request.</param> /// <returns>A collection of interceptors, ordered by the priority in which they should be invoked.</returns> public ICollection<IInterceptor> GetInterceptors(IProxyRequest request) { RuntimeMethodHandle methodHandle = request.Method.GetMethodHandle(); RuntimeTypeHandle typeHandle = request.Target.GetType().TypeHandle; ICollection<IInterceptor> interceptors = null; ConcurrentDictionary<RuntimeTypeHandle, List<IInterceptor>> methodCache = _cache.GetOrAdd(methodHandle, (RuntimeMethodHandle handle) => { return new ConcurrentDictionary<RuntimeTypeHandle, List<IInterceptor>>(); }); interceptors = methodCache.GetOrAdd(typeHandle, (RuntimeTypeHandle handle) => { if (!HasDynamicAdvice) { // If there are no dynamic interceptors defined, we can safely cache the results. Otherwise, we have // to evaluate and re-activate the interceptors each time. var interceptorsForRequest = GetInterceptorsForRequest(request); if (interceptorsForRequest != null) { return interceptorsForRequest.ToList(); } } return null; }); return interceptors ?? GetInterceptorsForRequest(request); }
/// <summary> /// Initializes a new instance of the <see cref="Invocation"/> class. /// </summary> /// <param name="request">The request, which describes the method call.</param> /// <param name="injector">The injector that will be used to call the target method.</param> /// <param name="interceptors">The chain of interceptors that will be executed before the target method is called.</param> public Invocation( IProxyRequest request, IMethodInjector injector, IEnumerable<IInterceptor> interceptors ) : base( request, interceptors ) { Ensure.ArgumentNotNull( injector, "injector" ); Injector = injector; }
public static MetricName BuildName(IProxyRequest request, string Name, bool Absolute) { MetricName metricName = null; if (Absolute) metricName = new MetricName(Name); else metricName = new MetricName(request.Target.GetType().FullName + "." + Name); return metricName; }
/// <summary> /// Creates the interceptor associated with the attribute. /// </summary> /// <param name="request">The request that is being intercepted.</param> /// <returns>The interceptor.</returns> public override IInterceptor CreateInterceptor( IProxyRequest request ) { Type targetType = request.Target.GetType(); Type serviceType = request.Kernel.GetBindings( DefaultServiceType ).Any() ? DefaultServiceType : DefaultInterceptorType; Type closedInterceptorType = serviceType.MakeGenericType( targetType ); var interceptor = (IInterceptor) request.Context.Kernel.Get( closedInterceptorType ); return interceptor; }
public override IInterceptor CreateInterceptor(IProxyRequest request) { if (meter == null) { MetricName metricName = Utils.BuildName(request, Name, Absolute); MetricRegistry registry = request.Context.Kernel.Get<MetricRegistry>(); meter = registry.Meter(metricName); } return new MeteringInterceptor(meter); }
public override IInterceptor CreateInterceptor(IProxyRequest request) { var interceptor = request.Kernel.Get<CacheInterceptor>(); if (DefaultTimeoutMinutes != 0) interceptor.Timeout = TimeSpan.FromMinutes(DefaultTimeoutMinutes); interceptor.CacheKeyPrefix = request.Target.GetType().FullName; return interceptor; }
/// <summary> /// Creates an executable invocation for the specified request. /// </summary> /// <param name="request">The request.</param> /// <returns>An executable invocation representing the specified request.</returns> public virtual IInvocation CreateInvocation( IProxyRequest request ) { IComponentContainer components = request.Context.Kernel.Components; IEnumerable<IInterceptor> interceptors = components.Get<IAdviceRegistry>().GetInterceptors( request ); IMethodInjector injector = components.Get<IInjectorFactory>().GetInjector( request.Method ); return new Invocation.Invocation( request, injector, interceptors ); }
public override IInterceptor CreateInterceptor(IProxyRequest request) { if (interceptor == null) { MetricName metricName = Utils.BuildName(request, Name, Absolute); MetricRegistry registry = request.Context.Kernel.Get<MetricRegistry>(); Counter counter = registry.Counter(metricName); interceptor = new CountingInterceptor(counter, Monotonic); } return interceptor; }
/// <summary> /// Initializes a new instance of the <see cref="InvocationBase"/> class. /// </summary> /// <param name="request">The request, which describes the method call.</param> /// <param name="interceptors">The chain of interceptors that will be executed before the target method is called.</param> protected InvocationBase( IProxyRequest request, IEnumerable<IInterceptor> interceptors ) { Ensure.ArgumentNotNull( request, "request" ); Request = request; Interceptors = interceptors; if ( interceptors != null ) { _enumerator = interceptors.GetEnumerator(); } }
public override IInterceptor CreateInterceptor(IProxyRequest request) { if (meterInterceptor == null) { MetricName metricName = Utils.BuildName(request, Name, Absolute); MetricRegistry registry = request.Context.Kernel.Get<MetricRegistry>(); Meter meter = registry.Meter(metricName); Type t = typeof(Exception); if (ExceptionType!=null && ExceptionType.IsSubclassOf(t)) t = ExceptionType; meterInterceptor = new ExceptionMeteringInterceptor(meter, t); } return meterInterceptor; }
private string GenerateCacheKey(IProxyRequest request) { var sb = new StringBuilder(); sb.Append(this.CacheKeyPrefix); sb.Append("."); sb.Append(request.Method.Name); sb.Append("."); foreach (object argument in request.Arguments) { if (argument is string && argument.ToString().Length < 50) // Preserve short string values for more readable key values sb.Append((string)argument); else sb.Append(argument.GetHashCode()); sb.Append("."); } sb.Remove(sb.Length - 1, 1); return sb.ToString(); }
public override IInterceptor CreateInterceptor(IProxyRequest request) { return(request.Kernel.Get <ISoapFaultHandlerInterceptor>()); }
/// <summary> /// Gets the interceptors that should be invoked for the specified request. /// </summary> /// <param name="request">The request.</param> /// <returns>A collection of interceptors, ordered by the priority in which they should be invoked.</returns> public ICollection<IInterceptor> GetInterceptors( IProxyRequest request ) { RuntimeMethodHandle methodHandle = request.Method.GetMethodHandle(); RuntimeTypeHandle typeHandle = request.Target.GetType().TypeHandle; ICollection<IInterceptor> interceptors = null; IDictionary<RuntimeTypeHandle, List<IInterceptor>> methodCache = null; lock (_cache) { if (!_cache.TryGetValue(methodHandle, out methodCache)) { methodCache = new Dictionary<RuntimeTypeHandle, List<IInterceptor>>(); _cache.Add(methodHandle, methodCache); } } lock (methodCache) { if (methodCache.ContainsKey(typeHandle)) { return methodCache[typeHandle]; } if (!HasDynamicAdvice) { interceptors = GetInterceptorsForRequest(request); // If there are no dynamic interceptors defined, we can safely cache the results. // Otherwise, we have to evaluate and re-activate the interceptors each time. methodCache.Add(typeHandle, interceptors.ToList()); } return interceptors ?? GetInterceptorsForRequest(request); } }
public override IInterceptor CreateInterceptor(IProxyRequest request) { return request.Kernel.Get<ITransactionInterceptor>(); }
public override IInterceptor CreateInterceptor(IProxyRequest request) { return(request.Kernel.Get <ICommitTransactionInterceptor>()); }
public override IInterceptor CreateInterceptor(IProxyRequest request) { return(new OverrideReturnInterceptor <int>(_returnValue)); }
/// <summary> /// Creates the interceptor associated with the attribute. /// </summary> /// <param name="request">The request that is being intercepted.</param> /// <returns>The interceptor.</returns> public override IInterceptor CreateInterceptor( IProxyRequest request ) { return CreateCallback( request ); }
/// <summary> /// Creates the interceptor associated with the attribute. /// </summary> /// <param name="request">The request that is being intercepted.</param> /// <returns>The interceptor.</returns> public abstract IInterceptor CreateInterceptor( IProxyRequest request );
public override IInterceptor CreateInterceptor(IProxyRequest request) { return new TransactionInterceptor(); }
public override IInterceptor CreateInterceptor(IProxyRequest request) { return(request.Context.Kernel.Get <UnitOfWorkAspect>()); }
/// <summary> /// Gets the interceptor associated with the advice for the specified request. /// </summary> /// <param name="request">The request in question.</param> /// <returns>The interceptor.</returns> public IInterceptor GetInterceptor(IProxyRequest request) { return(Interceptor ?? Callback(request)); }
/// <summary> /// Determines whether the advice matches the specified request. /// </summary> /// <param name="request">The request in question.</param> /// <returns><see langword="True"/> if the request matches, otherwise <see langword="false"/>.</returns> public bool Matches(IProxyRequest request) { return(IsDynamic ? Condition(request.Context) : MatchesMethod(request)); }
/// <summary> /// Creates the interceptor associated with the attribute. /// </summary> /// <param name="request">The request that is being intercepted.</param> /// <returns>The interceptor.</returns> public abstract IInterceptor CreateInterceptor(IProxyRequest request);
public override IInterceptor CreateInterceptor(IProxyRequest request) { return(request.Kernel.Get <EventLogInterceptor>()); }
public override IInterceptor CreateInterceptor(IProxyRequest request) { return(request.Kernel.Get <IAuthenticateUserInterceptor>()); }
public override IInterceptor CreateInterceptor( IProxyRequest request ) { return request.Context.Kernel.Get<FlagInterceptor>(); }
private ICollection<IInterceptor> GetInterceptorsForRequest(IProxyRequest request) { List<IAdvice> matches = _advice.Where(advice => advice.Matches(request)).ToList(); matches.Sort((lhs, rhs) => lhs.Order - rhs.Order); List<IInterceptor> interceptors = matches.Convert(a => a.GetInterceptor(request)).ToList(); return interceptors; }
public override IInterceptor CreateInterceptor(IProxyRequest request) { return(request.Context.Kernel.Get <RequiresDatabaseInterceptor>()); }
public override IInterceptor CreateInterceptor(IProxyRequest request) { return(request.Context.Kernel.Get <AuthenticationInterceptor>()); }
public override IInterceptor CreateInterceptor(IProxyRequest request) { return(request.Context.Kernel.Get <LoggingInterceptor>()); }
/// <summary> /// Evaluates if the method predicate matches. /// </summary> /// <param name="request">The request.</param> /// <returns><c>true</c> if the predicate matches, <c>false</c> otherwise.</returns> private bool MatchesMethodPredicate(IProxyRequest request) { if (MethodPredicate == null) { return true; } var requestMethod = request.Method; if (requestMethod.DeclaringType != request.Target.GetType()) { requestMethod = request.Target.GetType() .GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance) .SingleOrDefault(mi => mi.Name == requestMethod.Name && mi.GetParameters().SequenceEqual(requestMethod.GetParameters())) ?? requestMethod; } return this.MethodPredicate(requestMethod); }
public override IInterceptor CreateInterceptor(IProxyRequest request) { return new MethodInterceptor(); }
/// <summary> /// Evaluates if the method the method of this advice. /// </summary> /// <param name="request">The request.</param> /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns> private bool MatchesMethod(IProxyRequest request) { if (request.Method.GetMethodHandle().Equals(this.MethodHandle)) { return true; } var requestType = request.Method.DeclaringType; if (requestType == null || !requestType.IsInterface || !requestType.IsAssignableFrom(this.method.DeclaringType)) { return this.method.GetBaseDefinition().GetMethodHandle() == request.Method.GetMethodHandle(); } var map = this.method.DeclaringType.GetInterfaceMap(request.Method.DeclaringType); var index = Array.IndexOf(map.InterfaceMethods, request.Method.IsGenericMethod ? request.Method.GetGenericMethodDefinition() : request.Method); if (index == -1) { return false; } return map.TargetMethods[index].GetMethodHandle() == this.method.GetMethodHandle(); }
public override IInterceptor CreateInterceptor(IProxyRequest request) { return request.Kernel.Get<ProfileInterceptor>(); }
/// <summary> /// Gets the interceptor associated with the advice for the specified request. /// </summary> /// <param name="request">The request in question.</param> /// <returns>The interceptor.</returns> public IInterceptor GetInterceptor( IProxyRequest request ) { return Interceptor ?? Callback( request ); }
public override IInterceptor CreateInterceptor(IProxyRequest request) => request.Kernel.Get <ExceptionInterceptor>();
/// <summary> /// Gets the interceptors that should be invoked for the specified request. /// </summary> /// <param name="request">The request.</param> /// <returns>A collection of interceptors, ordered by the priority in which they should be invoked.</returns> public ICollection<IInterceptor> GetInterceptors( IProxyRequest request ) { RuntimeMethodHandle handle = request.Method.GetMethodHandle(); ICollection<IInterceptor> interceptors = null; lock ( _cache ) { if ( _cache.ContainsKey( handle ) ) { return _cache[handle]; } if ( HasDynamicAdvice && !_cache.ContainsKey( handle ) ) { interceptors = GetInterceptorsForRequest( request ); // If there are no dynamic interceptors defined, we can safely cache the results. // Otherwise, we have to evaluate and re-activate the interceptors each time. _cache.Add( handle, interceptors.ToList() ); } } return interceptors ?? GetInterceptorsForRequest( request ); }
/// <summary> /// Determines whether the advice matches the specified request. /// </summary> /// <param name="request">The request in question.</param> /// <returns><see langword="True"/> if the request matches, otherwise <see langword="false"/>.</returns> public bool Matches( IProxyRequest request ) { return IsDynamic ? Condition(request.Context) && MatchesMethodPredicate(request) : MatchesMethod(request); }
public override IInterceptor CreateInterceptor(IProxyRequest request) { return(request.Context.Kernel.Get <LastChanceWcfExceptionHandler>()); }