/// <summary>
 /// Get the list of behaviors for the current type so that it can be added to.
 /// </summary>
 /// <param name="policies">Policy list.</param>
 /// <param name="implementationType">Implementation type to set behaviors for.</param>
 /// <param name="name">Name type is registered under.</param>
 /// <returns>An instance of <see cref="InterceptionBehaviorsPolicy"/>.</returns>
 protected override InterceptionBehaviorsPolicy GetBehaviorsPolicy(IPolicyList policies, Type implementationType,
     string name)
 {
     var policy = policies.GetNoDefault<IInterceptionBehaviorsPolicy>(implementationType, false);
     if ((policy == null) || !(policy is InterceptionBehaviorsPolicy))
     {
         policy = new InterceptionBehaviorsPolicy();
         policies.Set(policy, implementationType);
     }
     return (InterceptionBehaviorsPolicy) policy;
 }
 /// <summary>
 /// Get the list of behaviors for the current type so that it can be added to.
 /// </summary>
 /// <param name="policies">Policy list.</param>
 /// <param name="implementationType">Implementation type to set behaviors for.</param>
 /// <param name="name">Name type is registered under.</param>
 /// <returns>An instance of <see cref="InterceptionBehaviorsPolicy"/>.</returns>
 protected override InterceptionBehaviorsPolicy GetBehaviorsPolicy(IPolicyList policies, Type implementationType,
     string name)
 {
     var policy = policies.GetNoDefault<IInterceptionBehaviorsPolicy>(implementationType, false);
     if ((policy == null) || !(policy is InterceptionBehaviorsPolicy))
     {
         policy = new InterceptionBehaviorsPolicy();
         policies.Set(policy, implementationType);
     }
     return (InterceptionBehaviorsPolicy) policy;
 }
        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.º 4
0
 internal static InterceptionBehaviorsPolicy GetOrCreate(
     IPolicyList policies,
     Type typeToCreate,
     string name)
 {
     NamedTypeBuildKey key = new NamedTypeBuildKey(typeToCreate, name);
     IInterceptionBehaviorsPolicy policy =
         policies.GetNoDefault<IInterceptionBehaviorsPolicy>(key, false);
     if ((policy == null) || !(policy is InterceptionBehaviorsPolicy))
     {
         policy = new InterceptionBehaviorsPolicy();
         policies.Set<IInterceptionBehaviorsPolicy>(policy, key);
     }
     return (InterceptionBehaviorsPolicy)policy;
 }
Ejemplo n.º 5
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);
        }
        internal static InterceptionBehaviorsPolicy GetOrCreate(
            IPolicyList policies,
            Type typeToCreate,
            string name)
        {
            NamedTypeBuildKey            key    = new NamedTypeBuildKey(typeToCreate, name);
            IInterceptionBehaviorsPolicy policy =
                policies.GetNoDefault <IInterceptionBehaviorsPolicy>(key, false);

            if ((policy == null) || !(policy is InterceptionBehaviorsPolicy))
            {
                policy = new InterceptionBehaviorsPolicy();
                policies.Set <IInterceptionBehaviorsPolicy>(policy, key);
            }
            return((InterceptionBehaviorsPolicy)policy);
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Get the list of behaviors for the current type so that it can be added to.
 /// </summary>
 /// <param name="policies">Policy list.</param>
 /// <param name="implementationType">Implementation type to set behaviors for.</param>
 /// <param name="name">Name type is registered under.</param>
 /// <returns>An instance of <see cref="InterceptionBehaviorsPolicy"/>.</returns>
 protected override InterceptionBehaviorsPolicy GetBehaviorsPolicy(IPolicyList policies, Type implementationType, string name)
 {
     return(InterceptionBehaviorsPolicy.GetOrCreate(policies, implementationType, name));
 }