castle-windsor Interceptors Interceptors can be chained in a fixed order


Example

For registration like this:

var container = new WindsorContainer();
container.Register(
    Component.For<FirstInterceptor>(),
    Component.For<SecondInterceptor>(),
    Component.For<ThirdInterceptor>(),

    Component.For<IService>()
        .ImplementedBy<Service>()
        .Interceptors<FirstInterceptor>()
        .Interceptors<SecondInterceptor>()
        .Interceptors<ThirdInterceptor>());

var service = container.Resolve<IService>();
service.CreateOrder(new Order());

With interceptors in the following spirit:

public class FirstInterceptor : IInterceptor
{
    public void Intercept(IInvocation invocation)
    {
        Console.WriteLine("First!");
        invocation.Proceed();
        Console.WriteLine("First.");
    }
}

And with service implemented in the following way:

public interface IService
{
    void CreateOrder(Order orderToCreate);
}

public class Service : IService
{
    public void CreateOrder(Order orderToCreate)
    {
        Console.WriteLine("Creating order...");

        // ...
    }
}

We can observe output that demonstrates interceptors created in a fixed order are going to be executed in that order:

First!
Second!
Third!
Creating order...
Third.
Second.
First.