I have a Castle Interceptor that I'm trying to apply via attributes. It's working great when I apply my Interceptor attribute at class-level, but it's not working at all when I'm applying at method-level. What am I doing wrong? I don't want to intercept every method on a class, but instead flag certain methods with the [Interceptor] attribute. I've tried marking my methods as virtual, but it still doesn't work. Here's my code:
This works and all methods are intercepted:
[Interceptor(typeof(CacheInterceptor))]
public class Foo : IFoo
{
public int SomeMethod() { }
}
This is NOT working (attribute is at method level):
public class Foo : IFoo
{
[Interceptor(typeof(CacheInterceptor))]
public int SomeMethod() { }
}
The installer:
public class CacheInterceptorInstaller : IWindsorInstaller
{
public void Install(IWindsorContainer container, IConfigurationStore store)
{
container.Register(Component.For<CacheInterceptor>().LifeStyle.Singleton);
container.Register(Component
.For<ICacheProvider>()
.LifeStyle.Singleton
.ImplementedBy<CacheProvider>());
}
}
The interceptor:
public class CacheInterceptor : IInterceptor
{
private readonly ICacheProvider _cacheProvider;
public CacheInterceptor(ICacheProvider cacheProvider)
{
_cacheProvider = cacheProvider;
}
public void Intercept(IInvocation invocation)
{
// do interception stuff
}
}
Thanks,
Andy