Please, look the code below. The Green test is OK because the interceptor is 
called but in the Red test the interceptor is skipped. Why?

Red test outputs : Executing context...
Green test outputs : Interceptor is called.

namespace TestWindsor
{
    [TestFixture]
    public class TestingInterceptors
    {
        [Test]
        public void Green()
        {
            var container = new WindsorContainer();
            container.Register(
                Component.For<SimpleInterceptor>(),
                
Component.For<IContext>().ImplementedBy<Context>().LifeStyle.Transient.Interceptors<SimpleInterceptor>()
                );
 
            var context = container.Resolve<IContext>();
            context.Execute();
        }
 
        [Test]
        public void Red()
        {
            var container = new WindsorContainer();
            container.Register(
                Component.For<SimpleInterceptor>(),
                
Component.For<Context>().LifeStyle.Transient.Interceptors<SimpleInterceptor>()
                );
 
            var context = container.Resolve<Context>();
            context.Execute();
        }
    }
 
    public interface IContext
    {
        void Execute();
    }
 
    public class Context : IContext
    {
        public void Execute()
        {
            Console.WriteLine("Executing context...");
        }
    }
 
    public class SimpleInterceptor : Castle.DynamicProxy.IInterceptor
    {
        public void Intercept(IInvocation invocation)
        {
            Console.WriteLine("Interceptor is called.");
        }
    }
}

-- 
You received this message because you are subscribed to the Google Groups 
"Castle Project Users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/castle-project-users/-/6XZPHpC8IK0J.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/castle-project-users?hl=en.

Reply via email to