AspectJ 和 PostSharp 之间的功能差异是什么?
有谁知道 AspectJ 和 PostSharp 之间的 AOP 功能有什么不同(是的,我知道它们适用于不同的语言和平台)?
我试图了解 AspectJ 允许做什么而 PostSharp 不允许,反之亦然。
Does anyone know what AOP features are different between AspectJ and PostSharp (yes I know they are for different languages and platforms)?
I'm trying to understand what kind of things AspectJ would allow that PostSharp would not, and vice versa.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
PostSharp 2.0 比 PostSharp 1.5 更接近 AspectJ。 PostSharp 1.5 与 Spring AOP 的比较是合理的,但与 PostSharp 2.0 的比较就不再合理了。
然而,在方法上仍然存在一些很大的差异。
切入点的方法完全不同。 AspectJ 提供了一种复杂的切入点语言。 PostSharp 提供了基本的声明性切入点系统但是使您能够开发命令式切入点,因此您可以编写在编译时评估切入点的代码(通常使用 System.Reflection)。因此,PostSharp 支持纯 C# 或 Linq,而不是切入点语言。
确实没有条件切入点(cflow)。
PostSharp 支持高阶语义,例如事件和属性。据我所知,AspectJ 没有(因为 Java 中没有事件或属性)。
PostSharp 方面通常在构建时实例化和初始化,然后序列化到程序集中,并在运行时反序列化以执行。这允许方面在构建时“初始化”,因此运行时性能更好。它还允许在构建时执行任意复杂的逻辑(通常是初始化、切入点评估、连接点验证)。
PostSharp 真正支持方面组合,即您可以以预测方式将多个方面或建议应用到同一连接点。 PostSharp 专为多供应商场景而设计,其中多个方面供应商彼此不了解。它有一个复杂的依赖系统,方面开发人员/供应商可以在其中以声明方式指定排序约束、要求和冲突。
从 2.0 版开始,PostSharp 附带了 IDE 工具,部分覆盖了 Eclipse 的“AJDT”功能。
PostSharp 2.0 is much closer to AspectJ than PostSharp 1.5 was. The comparison of PostSharp 1.5 to Spring AOP was justified, but is not any more with PostSharp 2.0.
However, there are still some strong differences in approach.
The approach to pointcuts is radically different. AspectJ provides a complex pointcut language. PostSharp provides a basic declarative pointcut system but enables you to develop imperative pointcuts, so you can write code (typically using System.Reflection) that evaluates the pointcut at compile time. So instead of having a pointcut language, PostSharp supports plain C# or Linq.
There is indeed no conditional pointcut (cflow).
PostSharp supports semantics of higher-order, like events and properties. AspectJ, to my knowledge, does not (since there is no event or property in Java afaik).
PostSharp aspects are typically instantiated and initialized at build time, then serialized into the assembly, and deserialized at runtime to be executed. This allows the aspect to "initialize" at build time, so runtime performance is better. It allows also to execute arbitrarily complex logic at build time (typically initialization, pointcut evaluation, joinpoint validation).
PostSharp has real support for aspect composition, i.e. you can apply multiple aspects or advices to the same joinpoint in a predictive way. PostSharp is designed for a multi-vendor scenario, where multiple aspect vendors don't know about each others. It has a complex system of dependencies, where aspect developers/vendors can specify declaratively ordering constraints, requirements and conflicts.
From version 2.0, PostSharp comes with IDE tooling that partly cover the functionality of "AJDT" for Eclipse.
来自他们的 PostSharp 文档:
http://doc.postsharp.org/ 1.5/##PostSharp.HxS/UserGuide/Laos/AspectKinds/Overview.html
支持的连接点类型:
http://doc.postsharp.org/ 1.5/##PostSharp.HxS/UserGuide/CoreLibrary/CodeWeaver/Overview.html
AspectJ 提供了更大的灵活性,因为连接点可以明显更复杂,以便执行您想要的操作。
例如,cflow 似乎无法使用 PostSharp 来完成。
它与 Spring 类似,是 AOP 的精简版本,以便更易于使用。
更新:虽然我不相信它已经完全更新,但对于 AspectJ 支持的内容来说这是一个好主意:
http://www.eclipse.org/aspectj/doc/released/ progguide/index.html
From their documentation of PostSharp:
http://doc.postsharp.org/1.5/##PostSharp.HxS/UserGuide/Laos/AspectKinds/Overview.html
Supported types of join points:
http://doc.postsharp.org/1.5/##PostSharp.HxS/UserGuide/CoreLibrary/CodeWeaver/Overview.html
AspectJ provides a great deal more flexibility as the join points can be decidedly more complex, in order to do what you want.
It appears that cflow, for example, can't be done with PostSharp.
It is like Spring in that it is a stripped down version of AOP in order to make it easier to use.
Update: Though I don't believe it is completely updated, this is a good idea as to what AspectJ supports:
http://www.eclipse.org/aspectj/doc/released/progguide/index.html