private IMessage ExecuteAddInterceptionBehavior(IMethodCallMessage callMessage)
        {
            IInterceptionBehavior interceptor = (IInterceptionBehavior)callMessage.InArgs[0];

            this.AddInterceptionBehavior(interceptor);
            return(new ReturnMessage(null, new object[0], 0, callMessage.LogicalCallContext, callMessage));
        }
Beispiel #2
0
        public BehaviorContainerExtension AddBehavior(IInterceptionBehavior behavior)
        {
            Guard.ArgumentIsNotNull(behavior, "behavior");

            _behaviors.Add(behavior);
            return(this);
        }
        public UnityInterfaceInterceptionRegister(Type[] interfaces, IInterceptionBehavior[] behaviors)
        {
            _interfaces.AddRange(interfaces);
            _interceptionBehaviors.AddRange(behaviors);

            ValidateInterfaces(_interfaces);
        }
        public static LambdaInstance <IServiceContext, TPluginType> InterceptWith <TPluginType, TPluginTypeProxy>(this ServiceRegistry.InstanceExpression <TPluginType> instance, String instanceName, Type behaviorType)
            where TPluginType : class
            where TPluginTypeProxy : TPluginType
        {
            IInterceptionBehavior behavior = (IInterceptionBehavior)Activator.CreateInstance(behaviorType);

            return(instance.InterceptWith <TPluginType, TPluginTypeProxy>(instanceName, behavior));
        }
        /// <summary>
        /// Creates a new instance of type <paramref name="type"/> that is intercepted with the behaviors in
        /// <paramref name="interceptionBehaviors"/>.
        /// </summary>
        /// <param name="type">The type of the object to create.</param>
        /// <param name="interceptionBehaviors">The interception behaviors for the new proxy.</param>
        /// <returns>An instance of a class compatible with <paramref name="type"/> that includes execution of the
        /// given <paramref name="interceptionBehaviors"/>.</returns>
        /// <exception cref="ArgumentException">when <paramref name="interceptor"/> cannot intercept
        /// <paramref name="type"/>.</exception>
        public static object NewInstance(Type type, IInterceptionBehavior interceptionBehavior)
        {
            var tuple = _typeInterceptor.CreateProxyType(type, true);
            var proxy = (IInterceptingProxy)tuple.Item2();

            proxy.AddInterceptionBehavior(interceptionBehavior);
            return(proxy);
        }
        /// <summary>
        /// Creates a new instance of type <typeparamref name="T"/> that is intercepted with the behaviors in
        /// <paramref name="interceptionBehaviors"/>.
        /// </summary>
        /// <typeparam name="T">The type of the object to create.</typeparam>
        /// <param name="interceptionBehaviors">The interception behaviors for the new proxy.</param>
        /// <param name="constructorParameters">The arguments for the creation of the new instance.</param>
        /// <returns>An instance of a class compatible with <typeparamref name="T"/> that includes execution of the
        /// given <paramref name="interceptionBehaviors"/>.</returns>
        /// <exception cref="ArgumentNullException">when <paramref name="interceptor"/> is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentNullException">when <paramref name="interceptionBehaviors"/> is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentException">when <paramref name="interceptor"/> cannot intercept
        /// <typeparamref name="T"/>.</exception>
        public static T NewInstance <T>(IInterceptionBehavior interceptionBehavior)
            where T : class
        {
            var proxy = ProxyCache <T> .Instance();

            ((IInterceptingProxy)proxy).AddInterceptionBehavior(interceptionBehavior);
            return(proxy);
        }
        public void VirtualInterceptionWithAdditionalInterfaces()
        {
            IInterceptionBehavior[] behaviourArray = new IInterceptionBehavior[1];
            behaviourArray[0] = new BehavourForAdditionalInterface();
            TestClass123 target          = new TestClass123();
            var          proxy           = (IAdditionalInterface)Intercept.NewInstanceWithAdditionalInterfaces <TestClass123>(new VirtualMethodInterceptor(), behaviourArray, new Type[] { typeof(IAdditionalInterface) });
            int          behaviourReturn = proxy.DoNothing();

            Assert.AreEqual <int>(100, behaviourReturn);
        }
        public void MBROInterceptionWithAdditionalInterfaces()
        {
            IInterceptionBehavior[] behaviourArray = new IInterceptionBehavior[1];
            behaviourArray[0] = new BehavourForAdditionalInterface();
            TestClass123 target          = new TestClass123();
            var          proxy           = (IAdditionalInterface)Intercept.ThroughProxyWithAdditionalInterfaces <TestClass123>(target, new TransparentProxyInterceptor(), behaviourArray, new Type[] { typeof(IAdditionalInterface) });
            int          behaviourReturn = proxy.DoNothing();

            Assert.AreEqual <int>(100, behaviourReturn);
        }
Beispiel #9
0
 public void MBROInterceptionWithoutAdditionalInterfaces()
 {
     DoNothingInterceptionBehavior.Reset();
     IInterceptionBehavior[] behaviourArray = new IInterceptionBehavior[1];
     behaviourArray[0] = new DoNothingInterceptionBehavior();
     ImplementsMBRO target = new ImplementsMBRO();
     ImplementsMBRO proxy = Intercept.ThroughProxy(target, new TransparentProxyInterceptor(), behaviourArray);
     proxy.TargetMethod();
     Assert.AreEqual("Called", DoNothingInterceptionBehavior.PreCalled);
     Assert.AreEqual("Called", DoNothingInterceptionBehavior.PostCalled);
 }
Beispiel #10
0
        public void VirtualInterceptionWithoutAdditionalInterfaces()
        {
            DoNothingInterceptionBehavior.Reset();
            IInterceptionBehavior[] behaviourArray = new IInterceptionBehavior[1];
            behaviourArray[0] = new DoNothingInterceptionBehavior();

            var proxy = Intercept.NewInstance<HasVirtualMethods>(new VirtualMethodInterceptor(), behaviourArray);
            proxy.TargetMethod();
            Assert.AreEqual("Called", DoNothingInterceptionBehavior.PreCalled);
            Assert.AreEqual("Called", DoNothingInterceptionBehavior.PostCalled);
        }
        public void VirtualInterceptionWithoutAdditionalInterfaces()
        {
            DoNothingInterceptionBehavior.Reset();
            IInterceptionBehavior[] behaviourArray = new IInterceptionBehavior[1];
            behaviourArray[0] = new DoNothingInterceptionBehavior();

            var proxy = Intercept.NewInstance <HasVirtualMethods>(new VirtualMethodInterceptor(), behaviourArray);

            proxy.TargetMethod();
            Assert.AreEqual("Called", DoNothingInterceptionBehavior.PreCalled);
            Assert.AreEqual("Called", DoNothingInterceptionBehavior.PostCalled);
        }
        public void MBROInterceptionWithoutAdditionalInterfaces()
        {
            DoNothingInterceptionBehavior.Reset();
            IInterceptionBehavior[] behaviourArray = new IInterceptionBehavior[1];
            behaviourArray[0] = new DoNothingInterceptionBehavior();
            ImplementsMBRO target = new ImplementsMBRO();
            ImplementsMBRO proxy  = Intercept.ThroughProxy(target, new TransparentProxyInterceptor(), behaviourArray);

            proxy.TargetMethod();
            Assert.AreEqual("Called", DoNothingInterceptionBehavior.PreCalled);
            Assert.AreEqual("Called", DoNothingInterceptionBehavior.PostCalled);
        }
Beispiel #13
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()));
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="InterceptionBehavior"/> with a 
 /// <see cref="IInterceptionBehavior"/>.
 /// </summary>
 /// <param name="interceptionBehavior">The interception behavior to use.</param>
 public InterceptionBehavior(IInterceptionBehavior interceptionBehavior) : base(interceptionBehavior)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="InterceptionBehavior"/> with a 
 /// <see cref="IInterceptionBehavior"/>.
 /// </summary>
 /// <param name="interceptionBehavior">The interception behavior to use.</param>
 protected InterceptionBehaviorBase(IInterceptionBehavior interceptionBehavior)
 {
     Guard.ArgumentNotNull(interceptionBehavior, "interceptionBehavior");
     this.explicitBehavior = interceptionBehavior;
 }
Beispiel #16
0
 public void AddBehavior(IInterceptionBehavior behavior)
 {
     _explicitBehaviors.Add(behavior);
 }
 public UnityInterfaceInterceptionRegisterer(Type interfaceType,
                                             IInterceptionBehavior interceptionBehavior)
 {
     interfaces.Add(interfaceType);
     behaviors.Add(interceptionBehavior);
 }
        public void AddInterceptionBehavior(IInterceptionBehavior interceptor)
        {
            Guard.ArgumentNotNull(interceptor, "interceptor");

            this.interceptorsPipeline.Add(interceptor);
        }
        /// <summary>
        /// Adds a <see cref="IInterceptionBehavior"/> to the proxy.
        /// </summary>
        /// <param name="interceptor">The <see cref="IInterceptionBehavior"/> to add.</param>
        public void AddInterceptionBehavior(IInterceptionBehavior interceptor)
        {
            Guard.ArgumentNotNull(interceptor, "interceptor");

            this.interceptorsPipeline.Add(interceptor);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="InterceptionBehavior"/> with a
 /// <see cref="IInterceptionBehavior"/>.
 /// </summary>
 /// <param name="interceptionBehavior">The interception behavior to use.</param>
 protected InterceptionBehaviorBase(IInterceptionBehavior interceptionBehavior)
 {
     Guard.ArgumentNotNull(interceptionBehavior, "interceptionBehavior");
     this.explicitBehavior = interceptionBehavior;
 }
 public static LambdaInstance <IServiceContext, TPluginType> InterceptWith <TPluginType, TPluginTypeProxy>(this ServiceRegistry.InstanceExpression <TPluginType> instance, String instanceName, IInterceptionBehavior behavior)
     where TPluginType : class
     where TPluginTypeProxy : TPluginType
 {
     return(instance.Use(InterceptorFunctionBuilder.Build <TPluginType, TPluginTypeProxy>(instanceName, behavior)).Named(instanceName));
 }
 /// <summary>
 /// Create a new <see cref="DefaultInterceptionBehavior"/> that will
 /// supply the given interception behavior to the container.
 /// </summary>
 /// <param name="interceptionBehavior">Behavior to apply to this type.</param>
 public DefaultInterceptionBehavior(IInterceptionBehavior interceptionBehavior) : base(interceptionBehavior)
 {
 }
 /// <summary>
 /// Adds a <see cref="IInterceptionBehavior"/> to the pipeline.
 /// </summary>
 /// <param name="interceptionBehavior">The interception behavior to add.</param>
 public void Add(IInterceptionBehavior interceptionBehavior)
 {
     _interceptionBehaviors.Add(interceptionBehavior ?? throw new ArgumentNullException(nameof(interceptionBehavior)));
 }
 public UnityInterfaceInterceptionRegister(Type interfaceType, IInterceptionBehavior behavior)
 {
     _interfaces.Add(interfaceType);
     _interceptionBehaviors.Add(behavior);
 }
Beispiel #25
0
 public object GetStickedObject(Type type, IInterceptionBehavior[] behaviors)
 {
     return Intercept.NewInstance(type, new VirtualMethodInterceptor(), behaviors);
 }
Beispiel #26
0
 /// <summary>
 /// Initializes a new instance of the <see cref="InterceptConfig"/> class.
 /// </summary>
 /// <param name="behavior">
 /// The behavior.
 /// </param>
 /// <param name="shouldIntercept">
 /// The should intercept.
 /// </param>
 public InterceptConfig(IInterceptionBehavior behavior, Func <RegisterEventArgs, bool> shouldIntercept)
     : this(new[] { behavior }, shouldIntercept)
 {
 }
Beispiel #27
0
 /// <summary>
 /// Initializes a new instance of the <see cref="IInterceptionBehavior"/> with a
 /// <see cref="IInterceptionBehavior"/>.
 /// </summary>
 /// <param name="interceptionBehavior">The interception behavior to use.</param>
 protected InterceptionBehaviorBase(IInterceptionBehavior interceptionBehavior)
 {
     _explicitBehavior = interceptionBehavior ?? throw new ArgumentNullException(nameof(interceptionBehavior));
 }
 public void AddInterceptionBehavior(IInterceptionBehavior interceptor)
 {
     throw new NotImplementedException();
 }
 /// <summary>
 /// Adds a <see cref="IInterceptionBehavior"/> to the pipeline.
 /// </summary>
 /// <param name="interceptionBehavior">The interception behavior to add.</param>
 public void Add(IInterceptionBehavior interceptionBehavior)
 {
     interceptionBehaviors = interceptionBehavior;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="InterceptionBehavior"/> with a
 /// <see cref="IInterceptionBehavior"/>.
 /// </summary>
 /// <param name="interceptionBehavior">The interception behavior to use.</param>
 public InterceptionBehavior(IInterceptionBehavior interceptionBehavior)
     : base(interceptionBehavior)
 {
 }
 public void AddInterceptionBehavior(IInterceptionBehavior interceptor)
 {
     pipeline.Add(interceptor);
 }
        private static Func <TPluginType, TPluginType> BuildInterceptorFunction <TPluginType>(IInterceptionBehavior behavior)
            where TPluginType : class
        {
            ICollection <IInterceptionBehavior> behaviors = new List <IInterceptionBehavior>();

            behaviors.Add(behavior);
            return(BuildInterceptorsFunction <TPluginType>(behaviors));
        }
        public static Func <IServiceContext, TPluginType> Build <TPluginType, TPluginTypeProxy>(String instanceName, IInterceptionBehavior behavior)
            where TPluginType : class
            where TPluginTypeProxy : TPluginType
        {
            Func <IServiceContext, TPluginType> proxyFunction = (context) =>
            {
                TPluginType service = context.GetInstance <TPluginTypeProxy>(instanceName);
                return(InterceptorFunctionBuilder.BuildInterceptorFunction <TPluginType>(behavior)(service));
            };

            return(proxyFunction);
        }
 /// <summary>
 /// Create a new <see cref="DefaultInterceptionBehavior"/> that will
 /// supply the given interception behavior to the container.
 /// </summary>
 /// <param name="interceptionBehavior">Behavior to apply to this type.</param>
 public DefaultInterceptionBehavior(IInterceptionBehavior interceptionBehavior)
     : base(interceptionBehavior)
 {
 }
Beispiel #35
0
        public void VirtualInterceptionWithAdditionalInterfaces()
        {
            IInterceptionBehavior[] behaviourArray = new IInterceptionBehavior[1];
            behaviourArray[0] = new BehavourForAdditionalInterface();
            TestClass123 target = new TestClass123();
            var proxy = (IAdditionalInterface)Intercept.NewInstanceWithAdditionalInterfaces<TestClass123>(new VirtualMethodInterceptor(), behaviourArray, new Type[] { typeof(IAdditionalInterface) });
            int behaviourReturn = proxy.DoNothing();

            Assert.AreEqual<int>(100, behaviourReturn);
        }
Beispiel #36
-1
        public void MBROInterceptionWithAdditionalInterfaces()
        {
            IInterceptionBehavior[] behaviourArray = new IInterceptionBehavior[1];
            behaviourArray[0] = new BehavourForAdditionalInterface();
            TestClass123 target = new TestClass123();
            var proxy = (IAdditionalInterface)Intercept.ThroughProxyWithAdditionalInterfaces<TestClass123>(target, new TransparentProxyInterceptor(), behaviourArray, new Type[] { typeof(IAdditionalInterface) });
            int behaviourReturn = proxy.DoNothing();

            Assert.AreEqual<int>(100, behaviourReturn);
        }