使用PostSharp拦截ADO.Net [英] Using PostSharp to intercept ADO.Net

查看:281
本文介绍了使用PostSharp拦截ADO.Net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有相当大的code。使用各种不同的ADO技术基础(如某些EF,在某些情况下,直接使用ADO.Net)。

I have quite a large code base using a variety of different ADO technologies (i.e. some EF and in some cases using ADO.Net directly).

我不知道是否有任何方式在全球范围内拦截任何ADO.Net调用,这样我就可以开始审计信息 - 即执行的确切的SQL语句,花费的时间,结果返回,等等

I'm wondering if there is any way to globally intercept any ADO.Net calls so that I can start auditing information - exact SQL statements that executed, time taken, results returned, etc.

主要的想法是,如果我能做到这一点,我不应该改变我的任何现有的code,我应该能够公正拦截/包裹ADO.Net称...这是可能吗?

The main idea being that if I can do this, I shouldn't have to change any of my existing code and that I should be able to just intercept/wrap the ADO.Net calls... Is this possible?

推荐答案

再思考是一个开源的工具支持修改现有的dll,而不需要从源代码重新编译添加方面的属性。对于这个工作,你需要创建修订在一个单独的DLL(你描述的再思考更改的方式),而这个DLL就需要有一个集级属性实施IAmendmentAttribute,将确定你的目标组装类型流程。

Afterthought is an open source tool that supports modifying an existing dll without requiring you to recompile from source to add aspect attributes. For this to work, you would need to create amendments (the way you describe your changes in Afterthought) in a separate dll, and this dll would need to have an assembly-level attribute implementing IAmendmentAttribute that would identify the types in your target assembly to process.

看看的记录例如来看看这是如何工作的让我知道,如果您有任何疑问/问题。

Take a look at the logging example to see how this works and let me know if you have any questions/issues.

请注意,修改的再思考你的目标组件来调用静态方法在其他组件(您的工具)。如果你想与修改目标组件以任何方式,那么我建议寻找到.NET分析API拦截来电。

Please note that Afterthought modifies your target assembly to make calls to static methods in another assembly (your tool). If you want to intercept calls with modifying the target assembly in any way, then I recommending looking into the .NET profiling API.

杰米·托马斯(事后反应,第一作者)

Jamie Thomas (primary author of Afterthought)

这篇关于使用PostSharp拦截ADO.Net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆