private void AddExplicitBehaviorPolicies(Type implementationType, string name, IPolicyList policies)
        {
            var lifetimeManager = new ContainerControlledLifetimeManager();

            lifetimeManager.SetValue(this.explicitBehavior);
            var behaviorName   = Guid.NewGuid().ToString();
            var newBehaviorKey = new NamedTypeBuildKey(this.explicitBehavior.GetType(), behaviorName);

            policies.Set <ILifetimePolicy>(lifetimeManager, newBehaviorKey);

            InterceptionBehaviorsPolicy behaviorsPolicy = this.GetBehaviorsPolicy(policies, implementationType, name);

            behaviorsPolicy.AddBehaviorKey(newBehaviorKey);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// API to configure the default interception settings for a type.
        /// </summary>
        /// <param name="typeToIntercept">Type the interception is being configured for.</param>
        /// <param name="interceptor">The interceptor to use by default.</param>
        /// <returns>This extension object.</returns>
        public Interception SetDefaultInterceptorFor(Type typeToIntercept, IInstanceInterceptor interceptor)
        {
            Guard.ArgumentNotNull(typeToIntercept, "typeToIntercept");
            Guard.ArgumentNotNull(interceptor, "interceptor");
            GuardTypeInterceptable(typeToIntercept, interceptor);

            Context.Policies.Set <IInstanceInterceptionPolicy>(new FixedInstanceInterceptionPolicy(interceptor), typeToIntercept);

            // 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, typeToIntercept);

            return(this);
        }