public override void PostBuildUp(IBuilderContext context)
        {
            Microsoft.Practices.Unity.Utility.Guard.ArgumentNotNull(context, "context");

            // If it's already been intercepted, don't do it again.
            if (context.Existing is IInterceptingProxy)
            {
                return;
            }

            IInstanceInterceptionPolicy interceptionPolicy =
                FindInterceptionPolicy <IInstanceInterceptionPolicy>(context, true);

            if (interceptionPolicy == null)
            {
                return;
            }

            var interceptor = interceptionPolicy.GetInterceptor(context);

            IInterceptionBehaviorsPolicy interceptionBehaviorsPolicy =
                FindInterceptionPolicy <IInterceptionBehaviorsPolicy>(context, true);

            if (interceptionBehaviorsPolicy == null)
            {
                return;
            }

            IAdditionalInterfacesPolicy additionalInterfacesPolicy =
                FindInterceptionPolicy <IAdditionalInterfacesPolicy>(context, false);
            IEnumerable <Type> additionalInterfaces =
                additionalInterfacesPolicy != null ? additionalInterfacesPolicy.AdditionalInterfaces : Type.EmptyTypes;

            Type typeToIntercept    = context.OriginalBuildKey.Type;
            Type implementationType = context.Existing.GetType();

            IInterceptionBehavior[] interceptionBehaviors =
                interceptionBehaviorsPolicy.GetEffectiveBehaviors(
                    context, interceptor, typeToIntercept, implementationType)
                .ToArray();

            if (interceptionBehaviors.Length > 0)
            {
                context.Existing =
                    Intercept.ThroughProxyWithAdditionalInterfaces(
                        typeToIntercept,
                        context.Existing,
                        interceptor,
                        interceptionBehaviors,
                        additionalInterfaces);
            }
        }
コード例 #2
0
 /// <summary>
 /// GetOrDefault the set of <see cref="IInterceptionBehavior"/> object to be used for the given type and
 /// interceptor.
 /// </summary>
 /// <remarks>
 /// This method will return a sequence of <see cref="IInterceptionBehavior"/>s. These behaviors will
 /// only be included if their <see cref="IInterceptionBehavior.WillExecute"/> properties are true.
 /// </remarks>
 /// <param name="context">Context for the current build operation.</param>
 /// <param name="interceptor">Interceptor that will be used to invoke the behavior.</param>
 /// <param name="typeToIntercept">Type that interception was requested on.</param>
 /// <param name="implementationType">Type that implements the interception.</param>
 /// <returns></returns>
 public static IEnumerable <IInterceptionBehavior> GetEffectiveBehaviors(this IInterceptionBehaviorsPolicy policy,
                                                                         ref BuilderContext context, IInterceptor interceptor,
                                                                         Type typeToIntercept, Type implementationType)
 {
     return(policy.GetEffectiveBehaviors(context.Container, interceptor, typeToIntercept, implementationType));
 }