Exemplo n.º 1
0
        /// <summary>
        /// API to configure interception for a type.
        /// </summary>
        /// <param name="typeToIntercept">Type to intercept.</param>
        /// <param name="name">Name type is registered under.</param>
        /// <param name="interceptor">Instance interceptor to use.</param>
        /// <returns>This extension object.</returns>
        public Interception SetInterceptorFor(Type typeToIntercept, string name, IInstanceInterceptor interceptor)
        {
            Guard.ArgumentNotNull(typeToIntercept, "typeToIntercept");
            Guard.ArgumentNotNull(interceptor, "interceptor");
            GuardTypeInterceptable(typeToIntercept, interceptor);

            var key = new NamedTypeBuildKey(typeToIntercept, name);

            var policy = new FixedInstanceInterceptionPolicy(interceptor);

            Context.Policies.Set <IInstanceInterceptionPolicy>(policy, key);

            // add policy injection behavior if using this configuration API to set the interceptor
            var interceptionBehaviorsPolicy = new InterceptionBehaviorsPolicy();

            interceptionBehaviorsPolicy.AddBehaviorKey(NamedTypeBuildKey.Make <PolicyInjectionBehavior>());
            Context.Policies.Set <IInterceptionBehaviorsPolicy>(interceptionBehaviorsPolicy, key);

            return(this);
        }
Exemplo n.º 2
0
        private void AddDefaultInstanceInterceptor(Type typeToIntercept, IPolicyList policies)
        {
            IInstanceInterceptionPolicy policy;

            if(interceptor != null)
            {
                policy = new FixedInstanceInterceptionPolicy((IInstanceInterceptor) interceptor);
            }
            else
            {
                policy = new ResolvedInstanceInterceptionPolicy(interceptorKey);
            }


            policies.Set<IInstanceInterceptionPolicy>(policy, typeToIntercept);
        }