Just create an interface like this:
public interface IMustBeIntercepted {}
and an object like this:
public class InterceptionFacility : AbstractFacility { protected override void Init() { Kernel.ComponentRegistered += new Castle.MicroKernel.ComponentDataDelegate(Kernel_ComponentRegistered); } void Kernel_ComponentRegistered(string key, Castle.MicroKernel.IHandler handler) { if(typeof(IMustBeIntercepted).IsAssignableFrom(handler.ComponentModel.Implementation)) { handler.ComponentModel.Interceptors.Add(new InterceptorReference(typeof(TestInterceptor))); } } }
Then register the object in the container using the <facility> . Now all components implementing IMustBeIntercepted will be intercepted by the TestInterceptor interceptor.
Mikael sundberg
source share