I have a lock interceptor that I am trying to apply through attributes. It works great when I apply the Interceptor attribute at the class level, but it doesn't work at all when I apply the method at the method level. What am I doing wrong? I don’t want to intercept every method in the class, but instead mark certain methods using the [Interceptor] attribute. I tried marking my methods as virtual, but this still doesn't work. Here is my code:
This works, and all methods are intercepted:
[Interceptor(typeof(CacheInterceptor))]
public class Foo : IFoo
{
public int SomeMethod() { }
}
This does NOT work (the attribute is at the method level):
public class Foo : IFoo
{
[Interceptor(typeof(CacheInterceptor))]
public int SomeMethod() { }
}
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>());
}
}
Interceptor:
public class CacheInterceptor : IInterceptor
{
private readonly ICacheProvider _cacheProvider;
public CacheInterceptor(ICacheProvider cacheProvider)
{
_cacheProvider = cacheProvider;
}
public void Intercept(IInvocation invocation)
{
}
}
Thanks,
Andy
source
share