Julian Jelfs’ Blog

Interceptor Selection with Castle Windsor

Posted in Castle by julianjelfs on March 27, 2009

As you may know it is possible to do some nice AOP type stuff by adding interceptors to objects served up using the Windsor container. It is also possible to inject interceptors on the fly using the interceptor selector extension point. I’m not going to talk about how that is done because that is very well described here.

I wanted to describe something that I thought was not obvious about the implemenation on this feature. I had assumed that if I returned false from IModelInterceptorSelectors.HasInterceptors then IModelInterceptorSelectors.SelectInterceptors would not be called. However, this is not the case. If the component already has interceptors, then IModelInterceptorSelectors.SelectInterceptors will be called regardless of what you return from IModelInterceptorSelectors.HasInterceptors.

This means that you really need to put your conditional logic to decide whether to dynamically inject interceptors into both interface implementations if there is any chance that the components already have interceptors.

This seems a bit wrong to me …. ?

A further gotcha is that the following approach for injecting an interceptor before other interceptors does not seem to work:

public InterceptorReference[] SelectInterceptors(ComponentModel model)



return model.Interceptors.ToArray();


because it throws an exception in the CopyTo method of the InterceptorsCollection. I found that the approach in the linked article above does work fine though (presumably because it does not involve converting the Interceptor reference collection to an array).

Tagged with:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: