简体   繁体   English

订阅正在执行的任何方法

[英]Subscribe to whatever method is being executed

In my app I'm creating an auditing package that obtains various information, one such type of information should provide different information regarding what method is executed (time it took to execute, method name, method class, assembly, etc). 在我的应用程序中,我正在创建一个获取各种信息的审核程序包,其中一种此类信息应提供有关执行哪种方法(执行时间,方法名称,方法类,程序集等)的不同信息。

I'm not looking to use an existing package or framework, but to create my own. 我不是要使用现有的程序包或框架,而是要创建自己的程序包或框架。

I can imagine that this is a complicated thing to do, but I'm looking for some pointers to get me started . 我可以想象这是一件复杂的事情,但是我正在寻找一些入门指南。

One option you may be interested in is DI-level interception. 您可能感兴趣的一种选择是DI级拦截。 Since container is responsible for your objects instantiation, sometimes it can be configured with proxy generators to enable call interception. 由于容器负责对象的实例化,因此有时可以使用代理生成器对其进行配置以启用呼叫拦截。

You can choose between Autofac , or Unity . 您可以在AutofacUnity之间进行选择。

The most popular tasks to solve with this approach are cross-cutting concerns, like: logging, measurements, run-time application structure analysis. 用这种方法解决的最流行的任务是跨领域的问题,例如:日志记录,测量,运行时应用程序结构分析。 If you don't want to pollute your code base with repetitive diagnostic code, just delegate this task to an interceptor. 如果您不想使用重复的诊断代码来污染您的代码库,只需将该任务委托给拦截器即可。

Similiar idea is AOP . 类似的想法是AOP I havn't seen popular AOP packages for a long time, and havn't used them, but it's worth to do a research on this topic too: 我已经很长时间没有见过流行的AOP软件包了,也没有使用过它们,但是也有必要对此主题进行研究:

What is the best implementation for AOP in .Net? .Net中AOP的最佳实现是什么?

DI Interception vs. AOP DI拦截vs. AOP

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM