开发者

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜