Interception Magic
September 27th, 2007 by TrilobyteHello, how are you? I am fine, thanks for asking. :S, anyway, in this post I will tell you about my first experience… with Windsor Castle interceptors that is. This morning, way to early, I tried to solve an access control problem: I needed to protect several WCF web services from unauthorized users. I was not very awake at the time so I came up with an easy, yet elegant, solution: use interceptors.
What are interceptors you might think, well, interceptors are class which intercept method calls for other classes. The purpose is to implement a common action, like: logging or authorization, they basically act as proxies. Castle Windsor allows you to configure interceptors in the application configuration file which solved my problem of having to modify all the service code myself.
Writing an interceptor for the Castle Windsor container is actually a simple and straightforward process: Create a new class and implement the IInterceptor interface which defines one single method: Intercept(IInvocation). The only thing left to do is to configure the component on which you want to apply the interceptor. That is it.
I am not going to explain all the details now, however I might write an article in the near future. That is it for now, until next time.