Exemplo n.º 1
0
        private void AddDefaultTypeInterceptor(Type typeToIntercept, IPolicyList policies)
        {
            ITypeInterceptionPolicy policy;

            if (this.interceptor != null)
            {
                policy = new FixedTypeInterceptionPolicy((ITypeInterceptor)this.interceptor);
            }
            else
            {
                policy = new ResolvedTypeInterceptionPolicy(this.interceptorKey);
            }

            policies.Set <ITypeInterceptionPolicy>(policy, typeToIntercept);
        }
Exemplo n.º 2
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">Interceptor to use.</param>
        /// <returns>This extension object.</returns>
        public Interception SetInterceptorFor(Type typeToIntercept, string name, ITypeInterceptor interceptor)
        {
            Guard.ArgumentNotNull(typeToIntercept, "typeToIntercept");
            Guard.ArgumentNotNull(interceptor, "interceptor");
            GuardTypeInterceptable(typeToIntercept, interceptor);

            var key = new NamedTypeBuildKey(typeToIntercept, name);

            var policy = new FixedTypeInterceptionPolicy(interceptor);

            Context.Policies.Set <ITypeInterceptionPolicy>(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);
        }