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

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

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

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

            behaviorsPolicy.AddBehaviorKey(newBehaviorKey);
        }
Пример #2
0
        /// <summary>
        /// Add policies to the <paramref name="policies"/> to configure the container to use the represented
        /// <see cref="IInterceptionBehavior"/> for the supplied parameters.
        /// </summary>
        /// <param name="serviceType">Interface being registered.</param>
        /// <param name="implementationType">Type to register.</param>
        /// <param name="name">Name used to resolve the type object.</param>
        /// <param name="policies">Policy list to add policies to.</param>
        public override void AddPolicies(Type serviceType, Type implementationType, string name, IPolicyList policies)
        {
            if (_explicitBehavior != null)
            {
                var lifetimeManager = new ContainerControlledLifetimeManager();
                lifetimeManager.SetValue(_explicitBehavior);
                var behaviorName   = Guid.NewGuid().ToString();
                var newBehaviorKey = new NamedTypeBuildKey(_explicitBehavior.GetType(), behaviorName);

                policies.Set(newBehaviorKey.Type, newBehaviorKey.Name, typeof(ILifetimePolicy), lifetimeManager);
                InterceptionBehaviorsPolicy behaviorsPolicy = GetBehaviorsPolicy(policies, serviceType, name);
                behaviorsPolicy.AddBehaviorKey(newBehaviorKey);
            }
            else
            {
                var behaviorsPolicy = GetBehaviorsPolicy(policies, serviceType, name);
                behaviorsPolicy.AddBehaviorKey(_behaviorKey);
            }
        }
Пример #3
0
        private static Castle.DynamicProxy.IInterceptor WrapInterceptorBehavior(IInterceptionBehavior behavior)
        {
            var syncBehavior = behavior as ISyncInterceptionBehavior;

            if (syncBehavior != null)
            {
                return(new SyncWrapperInterceptor(syncBehavior));
            }

            var asyncBehavior = behavior as IAsyncInterceptionBehavior;

            if (asyncBehavior != null)
            {
                return(new AsyncWrapperInterceptor(asyncBehavior));
            }

            throw new StructureMapException(string.Format(
                                                "{0} does not implement neither ISyncInterceptionBehavior nor IAsyncInterceptionBehavior",
                                                behavior.GetType().GetFullName()));
        }