首页 > 代码库 > 基于 .NET 的开源AOP框架评估

基于 .NET 的开源AOP框架评估


Rating of Open Source AOPFrameworks in .NET


基于 .NET的开源AOP框架评估


Introduction


引言


In the days where business agility is becoming thedefinite needof any business / IT infrastructure,quite frequentlywe areending up with facing scenarios where we need to developapplications that are flexible and easily manageable.


在业务灵活性逐渐成为业务和IT基础设施明确需求的时代,经常我们最终面对的情况是必须开发灵活的和容易管理的应用程序。


The flexibility in anapplication’s architecture is demanded by the emerging business competitions, pressureto sustain the challenges created by the innovative business models, need tosustain the growing customer’s base of an established business, etc. Say forexample you are building an e-commerce system with an innovative businessmodel, targeting a niche market. Soon, it is becoming hot in the market andyour system is witnessing a rapidly growing user base, in a short span of time.The system starts crawling, failing to sustain the increased user load there bycreating significant loss to your business and to the goodwill you have createdwith your hard work and innovation.


应用程序体系结构中的灵活性是由新兴的商业竞争所要求的,创新的商业模式创造了挑战性的持继压力,需要支持一个不断成长客户业务等。比如说你正在创建一个创新商业模式的电子商务系统,目标是一个利基市场。不久它将变成市场的热点并且你的系统将目睹快速增长的用户基数,在短短的时间内。系统开始运行缓慢,不能支撑的增长时用户负载,从而创造你的业务重大损失及你努力和创新建立的声誉。


Situations that may pull yourbusiness down may be like:


以下的情况可能会影响你的业务:


  • Changes in the regulations / policies of the government because of which you may need to incorporate some more rules into your system, while keeping it running


由于政府规章、政策的变化,你可能需要将一份策略融入你的系统并保持它的运行


  • Need to switch from your payment gateway to another one who is offering services at a discounted price, to increase the revenue


为了增加收入,需要去切换你的支付网关。这个新的网关提供了折扣服务。


  • Need to shift from one packaging company to other (like say from FedEx to UPS) as there is a need to increase of the speed of the delivery


为了提高投递速度,需要更换快递公司(比如说从FedEx更换为UPS


  • Demand to shift from a particular financial outsourcing services provider to another


需要更换特定金融服务提供商


  • Etc.


等等。


The architecture thatcould excel in such an agile environment can be called “PluggableArchitecture”. There are proven methodologies (Patterns) that can constitutethe design to realize such architectures. AOP is one of such available patterns/ methodologies widely adopted in the market.


像这样擅长灵活环境的体系结构可以称为可插拔式架构。有经过证实的方法论(模式)来构建这种架构的设计。AOP是在市场中被广泛采用的有效模式(方法论)。


Background


背景


AOP – Aspect OrientedProgramming is a methodology that helps in keeping the “cross-cutting concerns”separate from the code blocks that encapsulate business logic. “Cross-cutting”here refers to the code blocks that are non-business specific and that arerepeated across different classes spread across different layers. Examples ofcross cutting concerns are: Logging, Exception Handling code blocks specific toinstrumentation of the code, etc. There may be many numbers of such concernswhich need to be abstracted from the business logic specific code.


AOP——面向方面编程是一个方法论,它有助于横切关注点从你的业务逻辑封装中分离。横切在这里指的是非业务特定代码块及出现在不同类不同层次的重复代码块。横切关注点的例子:日志,特定的代码检测异常处理代码块等。可能有很多关注点需要从业务逻辑特定的代码中抽象出来。


The basic thumb rule toidentify a cross-cutting concern is: If a concern is repeated across classesspread over layers / tiers, then it is a cross-cutting concern.


识别一个横切关注点的经验法则是:如果一个关注点反复出现在不同类及层次中,那它是一个横切关注点。


AOPBenefits


AOP的好处


The facility to separate thecross-cutting concerns helps in:


1.    Selectively applying the crosscutting concerns, as required. Say some logic related to profilingthe code forperformance monitoring would be required only at the time of testing but not inthe production environment so they can be enabled/disabled based on theenvironment as required.


按照需求,可选择性的应用横切关注点。比如说一些用于性能监视的逻辑相关的分析代码仅在测试时是需要的,但在生产环境是不需要的,因此它们可以根据环境的需求而被启用或禁用。


2.    Applying any changes / fixingbugs in the cross-cutting code logic, without affecting the business logic codein the production environment.


在横切关注点逻辑中变更了代码或修正的缺陷,将不会影响生产影响中的业务逻辑代码。


3.    Evolution of the differentparts of the system in different paces.


不同系统的不同部分的进化。


4.    Arriving at a final solutionwhere the code is easy to understand and maintain


最终解决方案的代码是容易理解的和可维护的。


Need for a Rating Methodology


必要的评估方法


Having realizing the benefitsof AOP, the next step is to look for ways to implement it in our applicationdevelopment. In this case, instead of starting from scratch, the best way is to leverage theresearch and effort put by many hardworking tech savvies around the worldthrough the availability of open source frameworks / utilities.


了解了AOP的好处,下一步就去寻找在我们的应用开发中实现它的方法。最好的方法就是利用并研究世界上现有的开源框架或工具,努力的理解它们,这样我们就不需从头开始。


When we are in thestage of looking for adopting an open source AOP framework, lots of open sourceAOP frameworks are available in the market and hence, we need to choose thebest possible one for our development. Choosing the best possible one could be adifficult task as always there will be conflicts of thoughts and difference ofopinions, especially when we are in a team. Especially when we are in aposition to convince our customers for the adoption of a particular framework,we cannot choose a particular AOP framework, unless we have some goodjustifications.


当我们在寻找要使用的开源AOP框架的阶段,在市场上有很多可用的开源AOP框架,因此我们将为我们的开发选择一个最有潜力的。选择一个最有潜力的将是很困难的任务,因为通常会发生想法和意见的分歧,尤其当我们是一个团队时。最主要的是当我们站在自己的位置去说服我们的客户去采用一个特定的框架,除非我们想好了充分的理由,不然我们将不能去选择这个特定的AOP框架。


Will it not be good, if wehave rating methodology where we can analyze and evaluate the available AOPframeworks qualitatively and quantitatively enabling us to rate the AOPframeworks in the market so that we can make an informed decision in a shortspan of time. The result of such a thought process is the following “FrameworksRating Methodology”.


这样好不好,如果我们有一种评估的方法:让我们可以从质量和数量上分析和评价市场上AOP框架的可用性,并使我们在短时间内进行决策。像这种的思维过程就是以下的“框架评估方法”。


OpenSource AOP Frameworks Rating Methodology


开源AOP框架评估方法


As a part of this effort, Ihad identified some of the attributes (which can be expanded / refined) andassigned points for each of the AOP frameworks (which is subjective – It isbased on my research and information available to me. You can change it as peryour observation and conviction.)


作为尝试的一部分,我已经找出了一些特性(可以进行扩展或精减)并且为每种AOP框架进行了打分(这是主观给出的,它是基于我的研究和我所获取的信息。你可以依据你的观察和看法来个性它。)


The list of the open sourceAOP frameworks that areconsideredfor this rating process are:


下面列表了参与这个评估过程的开源AOP框架:


  • Aspect#
  • AspectDng
  • NAspect
  • PostSharp
  • Policy Injection Application Block
  • Sesar
  • Spring.NET [Spring.AOP]


The Rating attributesidentified and used for this rating process are:


评估特性及其在评估过程中的运用:


Quality of the Methodology adopted

实现方法的品质

There are different approaches available to achieve AOP in .NET. Each of the available open source AOP frameworks adopted different approaches. Basically AOP can be achieved either at compile time or at runtime. According to me, runtime will always be a overhead when compared to compile time, as it is a one time process. Details on the available approaches available at:http://www.ayende.com/Blog/archive/2007/07/02/7-Approaches-for-AOP-in-.Net.aspx When I was investigating the details of approach adopted by these open source frameworks, information clarity is available only for some of the frameworks. I had assigned points based on my thought process and perception. It may differ from person to person based on the availability of the information and depth of the research.

有不同的方法在 .NET下实现AOP。每一个可用的开源AOP框架都采用了不同的实现方法。从根本上来讲AOP可以在二个位置来实现:编译时和运行时。依我看运行时将比编译时多一些开销,因为它需要一点时间来处理。关于详细的可用实现方法见:AOP在 .NET中的七种实现方法

当我正在研究开源框架采用的详细实现方法时,发现仅有一些框架是信息透明的。我基于我的思维过程和看法进行了打分。它可以由于可用信息的不同和研究深度的不同而不同。

Community support

社区支持

When we choose a particular open source framework for our development projects, unless there is a wider community support, we cannot go with it, as it may be a high risk during the course of deployment or in the later stage of production support.

当我们在我们的开发项目中选择一个特定的开源框架时,除非它们有一个较广泛的社区支持,否则我们不应该选择它,因为它在部署实施期间或产品维护支持阶段存在很高的风险。

Visibility of any Implementations / Industry-wide adoption

实现的可见性或采用的广泛性

Again, as a part of finalizing architecture for a solution, our clients may be looking for proven case studies / industry wide adoptions of the products that we choose. The same thing is applicable here as well. Availability of proven case studies will provide us some confidence on that framework especially when we go for large scale, enterprise level solution development. In this investigation process, I could rarely see any proven case studies for any of these listed frameworks.

此外,作为解决方案最终构架的一部分,我们的客户可能会寻找经过验证的案例研究或业内广泛采用的产品供我们选择。同样的事情在这里一样适用。尤其当框架被应用到大规模企业级解决方案开发时经过可用性验证的案例将提供给我们很大的信心。

Ease of adoption by developers

开发中使用的难易度

This is again subjective and can vary from person to person.

这是一个主客评价,并且可以因人而异。

Learning curve required

学习曲线

This is again subjective and can vary from person to person.

这是一个主客评价,并且可以因人而异。

Memory Footprint / overhead

内存占用/开销

This could be a key attribute on rating a particular framework. Only some of the framework’s groups are explicit on memory foot print of their products. As this could be a significant factor affecting the performance and resource consumption especially on large scale deployments, I would suggest the respective framework providers to publish benchmark case studies / lab results, which would provide us good confidence on the framework.

这可能是评估一个特定框架的关键特性。仅有一些框架在它们的产品中显式说明了内存占用。这可能是影响性能和资源占用的重要因素,尤其是在大规模部署上。我建议研究各框架提供的基准案例或实验结果,这些内容会为我们选择框架提供更多的信心。

Available version in the market (Is it a RC or still inalphastage)/ Documentation

市场上的可用版本(RC或仍处于开发阶段)/文档

Some of the frameworks on its early stages development. Periodical releases of the subsequent versions of the frameworks are the indications of the aggressive development and enthusiasm of the community behind those frameworks. Also, availability of the documentation (API, Conceptual, and Architecture) is a definite need for any framework to understand them clearly.

一些框架还存在早期的发展阶段。框架的周期性的版本发布标志着它的积极发展和其社区的热情。同样,文档(API、概念和结构)是明确理解框架所必需的。


I have assigned very lowpoints if the information is not clear or if it is not available or if it isvague.


如果信息不是明确的或不是有效的或很模糊的,我将给出很低的分数。


Guidance for Rating Attributes


评估特性等级


  • 0 – bad, Not known, Not clear, sufficient information not available


0—不好的,不理解的,不明确的,有效信息不足


  • 1 – To be improved, some information is available


1—需改进的,有部分有效信息


  • 2 – Good, sufficient information is available


2—良好的,有足够的有效信息


  • 3 – Very good, no major overhead, no major memory footprint, excellent information is available


3—非常好,适合的开销,适合的内存占用,丰富的有效信息


Here is the resultingrating matrix:


以下是评估结果:


Preliminary Rating Matrix

初步评估矩阵

Available Open Source .NET AOP Frameworks / Utilities

可用的开源 .NET AOP框架/工具

 

NAspect –Puzzle.
Net

Aspect#

Policy Injection Application Block

PostSharp

Seasar

Aspect
Dng

Spring.Net

Quality of the Methodology adopted

实现方法的品质

2

2

2

3

2

2

2

Community support

社区支持

2

2

3

3

1

1

3

Visibility of any Implementations / Industry-wide adoption

实现的可见性或采用的广泛性

1

0

2

2

0

0

1

Ease of adoption by developers

开发中使用的难易度

2

1

2

3

2

1

2

Learning curve required

学习曲线

1

1

2

3

1

1

2

Memory Footprint / overhead

内存占用/开销

1

0

1

3

0

0

1

Available version in the market (Is it a RC or still in alpha stage)/ Documentation

市场上的可用版(RC或仍处于开发阶段)/文档)

2

2

3

3

2

1

3

Total

合计

11

8

15

20

8

6

14


 


Conclusion


结论


Whenever we go forimplementing a particular methodology or concept like AOP, we will alwaysleverage the existing open source frameworks. Since there are a number of opensource frameworks available in the market, it will always be good to have someconcrete justifications as a base for selecting a particular framework foradoption.


无论何时我们想去实施像AOP这样的特定方法或想法,我们通常会利用现存的开源框架。自从在市场上出现很多可用的开源框架之后,我们通常会有很多具体的理由作为选择采用框架的基础。


Adopting a ratingprocess like the one explained in this article will ensure that theframeworks are subjected to both qualitative & quantitative evaluationprocess, resulting in a meaningful decision.


采用像这篇文章中介绍的评估过程,从质量和数量上为决策提供有意图的信息。


From the matrix, the frameworks thatemerged in the ‘top 3 ‘list of are:


下面列表了前3位的框架:


  • PostSharp
  • Policy Injection Application Block
  • Spring.Net [Spring.AOP]


 


原始地址:http://www.codeproject.com/Articles/28387/Rating-of-Open-Source-AOP-Frameworks-in-NET


基于 .NET 的开源AOP框架评估