How to intercept an IInvocation using dynamic proxy?
Is it possible to intercept an IInvocation using dynamic proxy and windsor (if windsor is even needed for such a case. I am using it to configure the proxy generation though)?
I would like to log that an interception has changed th开发者_JAVA百科e call to the intercepted method. For example the passed arguments were changed or the return value. Note that this is for debug only purposes.Follow the code below:
public class TransactionInterceptor : IInterceptor
{
private readonly IUnitOfWork _UnitOfWork;
public TransactionInterceptor(IUnitOfWork unitOfWork)
{
_UnitOfWork = unitOfWork;
}
public void Intercept(IInvocation invocation)
{
_UnitOfWork.Begin();
try
{
invocation.Proceed();
_UnitOfWork.Commit();
}
catch (Exception)
{
_UnitOfWork.RollBack();
throw;
}
}
}
Yes, its possible, I recommend to read this
精彩评论