C#面向切面编程

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1416880/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 16:18:41  来源:igfitidea点击:

Aspect Oriented Programming in C#

c#.netaop

提问by TheVillageIdiot

Are there any good resources to wrap my head around Aspect Oriented Programming?

有没有什么好的资源可以让我了解面向方面的编程?

PS: I need to understand AO programming, not the libraries or frameworks available for .NET or C# :)

PS:我需要了解 AO 编程,而不是可用于 .NET 或 C# 的库或框架:)

采纳答案by Noon Silk

Just to get your head around it: It is the ability to hookevents such as: creation of objects, setting of properties, etc, and attach general functions to them, that will be populated with relevant context.

只是为了让您了解它:它能够挂钩事件,例如:对象的创建、属性的设置等,并将通用函数附加到它们,这些函数将填充相关上下文。

Because C# doesn't have an inbuilt facility for this, you need a framework, like PostSharp, to do 'bytecode weaving' (i.e. just writing code to actually make the calls, directly to your classes) to simulate it.

因为 C# 没有为此内置工具,所以您需要一个框架,如 PostSharp,来进行“字节码编织”(即,只需编写代码来实际进行调用,直接对您的类)来模拟它。

回答by codymanix

Aspect Oriented Programming means having a meta level where yo can define logging or security/access control features to interweave with your code instead of implementing these feature very time in your code. So instead of beeing one-dimensional, you have to program two-dimensional.

面向方面的编程意味着拥有一个元级别,您可以在其中定义日志记录或安全/访问控制功能以与您的代码交织在一起,而不是在您的代码中经常实现这些功能。因此,您必须编程二维而不是一维。

I know this may sound very esotheric but it is easy once you understood it.

我知道这听起来可能很深奥,但一旦你理解它就很容易了。

AOP often works with proxy classes which intercept calls and do things in the background.

AOP 经常与代理类一起工作,这些代理类拦截调用并在后台执行操作。

回答by shahkalpesh

What a timely question?

多么及时的问题?

Hereis the podcast worth listening.
This will give you a good overview on what is AOP? where it can be used?

是值得一听的播客。
这将使您对什么是 AOP 有一个很好的概述?在哪里可以使用?

Hope that helps.

希望有帮助。

回答by Jean-Pierre Fouché

A good link below, shows you how to code up an AOP framework of your own. Unfortunately, all of your consuming classes have to inherit from the MarshalByRefObject(through ContextBoundObject).

下面有一个很好的链接,向您展示了如何编写自己的 AOP 框架。不幸的是,您所有的消费类都必须从MarshalByRefObject(通过ContextBoundObject)继承。

http://www.developerfusion.com/article/5307/aspect-oriented-programming-using-net/3/

http://www.developerfusion.com/article/5307/aspect-oriented-programming-using-net/3/

回答by Muhammad Soliman

check this out, it is describing how to implement AOP ( log, timing, tracing, exception handling...) using postsharp

看看这个,它描述了如何使用 postsharp 实现 AOP(日志、计时、跟踪、异常处理...)

http://www.codeproject.com/Articles/337564/Aspect-Oriented-Programming-Using-Csharp-and-PostS

http://www.codeproject.com/Articles/337564/Aspect-Oriented-Programming-Using-Csharp-and-PostS