`
joerong666
  • 浏览: 411065 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

10分钟入门AOP:用PostSharp普及一下AOP

阅读更多

10分钟入门AOP:用PostSharp普及一下AOP

PostSharp是一个比较强调易学易用的AOP框架,在这之前我接触过AspectJ,Spring.当然花的时间也不多,不过一直感觉不好掌握,似乎AOP是比较难的东西。今天看到这篇英文论文里面的说明,似乎并不那么难以掌握。参考下图,对比一下两组概念。


PS用了我们熟知的东西,而没有引入新名词,这是它聪明的地方。看表格右边的一组概念,事件(还不太理解为什么说是meta),事件处理器,aspect=定制的attribute, 唯一新鲜的是multicasting,实际上可以理解为一个通配表达式。

下面再用一个简单例子:

<!---->public class LogAttribute : OnMethodBoundaryAspect
{
public override void OnEntry (MethodExecutionEventArgs eventArgs )
{  Console . WriteLine (" Entering the method {0}." , eventArgs . Method );
}

public override void OnExit (MethodExecutionEventArgs eventArgs )
{
  Console . WriteLine (
" Leaving the method {0}." , eventArgs . Method );
}

}


class Program
{
[Log]
static void Main ()
{
    Console . WriteLine (" Hello , world .");
}
}

//multicasting 说明对
MyApp . BusinessObjects命名空间使用Log

[ assembly : Log(
AttributeTargetTypes =
" MyApp . BusinessObjects .*" ,
AttributeTargetMemberAttributes =
MulticastAttributes . Public )]

从这例子看非常简明清晰,的确易学易用。

分享到:
评论

相关推荐

    aop demo PostSharp

    vs2010 + postsharp 2.0 AOP DEMO 需要安装 postsharp 2.0

    PostSharp实现AOP 实例

    PostSharp工具实现AOP 拦截,获取拦截方法的所有参数,并得到所有参数值。

    AOP.in..NET

    AOP in .NET: Practical Aspect-Oriented Programming 296 pages Publisher: Manning Publications; Pap/Psc edition (June 25, 2013) Language: English ISBN-10: 1617291145 ISBN-13: 978-1617291142 ...

    PostSharp1.5安装包(X86和X64)以及示例

    PostSharp使用静态织入方式实现AOP,其连接点非常丰富,使用简单,而且相对其它一些.NET平台上的AOP框架来说,PostSharp较为轻量级,但是功能却一点也不逊色,因此是我比较喜欢的一个AOP框架。更多关于PostSharp的...

    [AOP编程框架].Sharpcrafters.PostSharp.v2.0.9.3

    [AOP编程框架].Sharpcrafters.PostSharp.v2.0.9.3.Incl.Keygen.and.Patch.REPACK-Lz0.zip

    PostSharp 2.0

    PostSharp 2.0 C# AOP 框架

    PostSharp.Samples:PostSharp示例

    欢迎使用此PostSharp示例项目集合。 您可以并通过单击代码引用来导航代码,也可以将它们下载到。 项目 描述 方面框架 记录方法调用,包括参数值。 缓存方法调用的结果 将参数值添加到异常详细信息中的调用堆栈...

    PostSharp2.0.8安装文件

    postsharp组件,vs2010中使用,aop亲测可用

    PostSharp 2.1 - Sample Code

    PostSharp 2.1例子。是学习c# AOP编程必备资料。

    PostSharp3.0

    著名的AOP框架之一,PostSharp3.0,3.0支持vs12应该。文件中包含注册机,可以联网注册。压缩包只有3.0的vsix插件,建议去官网下载最新版的4.0.1使用。另外啰嗦一下,不喜勿碰,下载杀毒,喷子回避,自己悄悄用就好,...

    SharpCrafters PostSharp Ultimate 5.0.44(含key)

    PostSharp是一个非常优秀的AOP框架,使用上非常方便,功能强大,对目标拦截的方法不需要做什么修改,但现在已经商业化运作 Notes: All vsix files repacked with cracked PostSharp.Compiler.Settings.dll

    基于.NET平台C#开发实现的AOP日历管理系统

    日历管理系统是用C#开发的,通过.NET平台下AOP的Postsharp增加了日志管理和异常处理的功能,附带的文档是关于AOP的技术文档。

    PostSharp source code 源代码

    Postsharp 是C#最知名的AOP框架, 最初是开源项目,目前已经商业化运作,网络上很难找到源代码,这里提供PostSharp 早起版本的源代码,以供学习。ostSharp是一种Aspect Oriented Programming 面向切面(或面向方面)...

    PostSharp 支持vs2017

    PostSharp solves this by extending the C# and VB languages with a notion of pattern. It includes ready-made implementations of the most common patterns found in .NET and gives you a framework to ...

    AOP in .NET

    Aspect-oriented programming (AOP) is a concept that is too often surrounded by dense language and academic terminology, which can make it difficult for a working developer—who is already short on ...

    浅谈C# AOP的简单实现

    这篇打算写写AOP,说起AOP,其实博主接触这个概念也才几个月,了解后才知道,原来之前自己写的好多代码原理就是基于AOP的,比如MVC的过滤器Filter,它里面的异常捕捉可以通过FilterAttribute,IExceptionFilter去处理...

    使用C#和PostSharp进行面向方面的编程

    本文讨论AOP中的基本概念,并使用PostSharp在C#应用程序中实现AOP概念。

Global site tag (gtag.js) - Google Analytics