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.");
}
}
}