예제 #1
0
        /// <summary>
        /// Intercepts the specified invocation.
        /// </summary>
        /// <param name="invocation">The invocation.</param>
        public void Intercept(IInvocation invocation)
        {
            var interceptors        = Configuration.Interceptors;
            var orderedInterceptors = SortOrderFactory.GetSortOrderStrategy(invocation, interceptors).Sort();
            var validInterceptors   = (from interceptor in orderedInterceptors
                                       where Interception.DoesTargetMethodHaveAttribute(invocation, interceptor.TargetAttributeType)
                                       select ResolveHowToCreateInterceptor(interceptor).Create(interceptor)).ToList();

            // 2012.05.14 -tyler brinks - Apparently it is no longer necessary with the new version of Castle to do
            // the "false" interceptions unless they exist without a valid interceptor.
            var falseInvocations = orderedInterceptors.Count() - validInterceptors.Count();

            if (falseInvocations > 0 /*&& validInterceptors.Count == 0*/)
            {
                for (var i = 0; i < falseInvocations; i++)
                {
                    // Not all interceptors run for each type, but all interceptors are interrogated.
                    // If there are 5 interceptors, but only 1 attribute, this handles the other 4
                    // necessary invocations.
                    invocation.Proceed();
                }
            }

            foreach (var interceptor in validInterceptors)
            {
                interceptor.BeforeInvocation();
                interceptor.Intercept(invocation);
                interceptor.AfterInvocation();
            }

            if (ResetPseudoInterceptors != null)
            {
                ResetPseudoInterceptors();
            }
        }
예제 #2
0
 /// <summary>
 /// Determines whether a type shoulds be intercepted by this interceptor.
 /// </summary>
 /// <param name="invocation">The invocation.</param>
 /// <remarks>
 /// Actually we do not need this method here anymore.
 /// The responsibility of checking which interceptors should be run is moved to <see cref="MasterProxy">MasterProxy</see> class.
 /// The method is left to avoid breaking existing <see cref="IAttributeInterceptor">IAttributeInterceptor</see> contract.
 /// </remarks>
 /// <returns></returns>
 public bool ShouldIntercept(IInvocation invocation)
 {
     // just delegate it to Interception class
     return(Interception.DoesTargetMethodHaveAttribute(invocation, TargetAttribute));
 }