使用AOP技术拦截ADO.Net [英] Using AOP techniques to intercept ADO.Net
问题描述
我有相当大的$ c。使用各种不同的ADO技术,$ C碱基(即一些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 like, 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... Is this possible?
修改
它已建议我看看 PostSharp ,的 CciSharp 或的再思考,但我怎么用其中的一个,以获得想要的结果?
Its been suggested that I look into PostSharp, CciSharp or Afterthought, but how do I use one of these to get the desired results?
推荐答案
没有。 如果您是直接编码对ADO.NET类型的,你不能只是告诉DynamicProxy:哎,把代理,无论我在所有这些DLL使用的SqlConnection。 DynamicProxy是的运行的代理生成。看来你想要的后编译的AOP,所以考虑 PostSharp ,< A HREF =?HTTP://ccisamples.$c$cplex.com/wikipage标题= CciSharp和放大器; referringTitle =家相对=nofollow> CciSharp 或的再思考代替。
No. If you're coding directly against ADO.NET types you can't just tell DynamicProxy: "hey, put a proxy wherever I use SqlConnection in all these DLLs". DynamicProxy is a runtime proxy generator. It seems that you want post-compilation AOP, so look into PostSharp, CciSharp or Afterthought instead.
编辑:如果没有这些工具是不够的,你可以使用Mono.Cecil能做到直接修改你的信息素养,但是,这并不容易。参见例如:
if none of those tools are enough, you could use Mono.Cecil to directly alter your IL, but it's not easy. See for example:
- 的http://www.$c$cthinked.com/static-method-interception-in-net-with-c-and-monocecil
- <一个href="http://stackoverflow.com/questions/4372205/how-to-inject-call-to-system-object-equals-with-mono-cecil">How来电System.Object.Equals与Mono.Cecil能做到注入?
- http://www.codethinked.com/static-method-interception-in-net-with-c-and-monocecil
- How to inject call to System.Object.Equals with Mono.Cecil?
这篇关于使用AOP技术拦截ADO.Net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!