Friends, Technology, Web2.0 - What I am reading

    [Home] [Recent] [Site Map]

   

Policy Injection Application Block

Microsoft Patterns & Practices团队在2007年发布的Enterprise Library 3.0 February 2007 CTP中,我们惊喜地发现了AOP的踪迹,其名为Policy Injection Application Block(PIAB)。Enterprise Library的产品经理Tom Hollander和架构师Edward Jezierski都相继在自己的博客上介绍了PIAB。从特征与功能来看,已经基本具备了AOP的要求。

从技术实现来看,PIAB并没有特别的创新,沿用了大多数致力于.NET平台AOP研究人员的思路,采用了Remoting Proxy技术。PIAB定义了特殊的工厂类,通过它添加Policy,然后创建代理对象实例。受到Remoting Proxy技术的限制,所谓的代理对象必须继承自MashalByRefObject。例如:
public class LoggingTarget : MarshalByRefObject
{
    public string DoSomething(int one, string two, double three)
    {
        return string.Format("{1}: {0} {2}", one, two, three);
    }
}

添加Policy与创建Aspect对象的方法如下:
private PolicySet GetLoggingPolicies()
{
    PolicySet policies = new PolicySet();

    Policy simpleInputsPolicy = new Policy("simpleInputsPolicy");
    simpleInputsPolicy.RuleSet.Add(new MatchByNameRule("MethodWithSimpleInputs"));
    simpleInputsPolicy.Handlers.Add(new SignatureCheckingHandler(new Type[] { typeof(int), typeof(string) }));
    policies.Add(simpleInputsPolicy);
    return policies;
}
private LoggingTarget CreateTarget()
{
    InterceptionFactory factory = new InterceptionFactory();
    factory.AddPolicies(GetLoggingPolicies());
    return factory.CreateNew<LoggingTarget>();
}

代理对象(Proxy Object)会通过Handler链定位到真实对象(Real Object),而Policy则被注入到代理对象和真实对象中。整个流程如图:

PIABIntroPipeline.gif

在Policy中,包含了一个Matching Rules集合以及Handlers Pipeline。从AOP技术的角度来看,代理对象所指代的真实对象就是“Aspect”,而Policy则是切入点,它可以通过Matching Rules来定位代理对象的方法,至于Handler则近似于Advise。

Authorization横切关注点(Cross-Cutting Concerns)的处理方式如图所示:

PIABaborted.png

PIAB目前预定义的Handler包括Validation Handler、Logging Handler、Exception Handling Handler、Authorization Handler、Caching Handler。这些Handler与Enterprise Library中的其他Application Block几乎是一一对应的。事实上,权限认证、日志、异常处理、缓存等,恰恰都是AOP技术最重要的关注点。在February 2007 CTP版本之前的Application Block,实际上已经具备了AOP的雏形。然后,由于它在“横切”与“注入”方面的缺乏,始终无法达到AOP所要求的重用目的。Policy Injection Application Block正好弥补了这样的缺憾。

本人也曾利用Remoting Proxy技术开发了.NET平台下的AOP组件,基本实现了AOP的主要功能。然后因为两个困惑,使得这一工作没有继续进行下去。

1、使Aspect对象继承自MarshalByRefObject是否过于专制?鉴于许多语言都具备单继承的特性,如果剥夺了一个类继承的能力,就使得程序的设计者多了很多约束。这是否是明智的选择呢?

2、继承自MarshalByRefObject后,效率究竟如何?我曾经做个这样的测试,发现继承自MarshalByRefObject类的对象比没有继承MarshalByRefObject类的对象,在性能上相差了几十倍。PIAB采用Remoting Proxy技术,是否在性能上有所考虑呢?


>>Source Link
>>Blog: joycode
>>Publish Date: 3/21/2007 1:00:26 PM
>>Keywords: policy handler

Related Posts
>>Google Updates AdSense Policies #
    Google updated its policies for publishers in the AdSense program last night. Jennifer Slegg has a very thorough breakdown of the changes, with special attention to the competitive ad policy.
>>YouTube antipiracy software policy draws fire (Reuters) #
    YouTube antipiracy software policy draws fire — The media industry is clashing with YouTube over its proposal to offer antipiracy tools only to companies that have distribution deals with the
>>RIAA Adopts New Policy, offers "Pre-Doe settlement option" ... (Ray Beckerman/Recording Industry vs ...) #
    RIAA Adopts New Policy, offers "Pre-Doe settlement option" if ISP Holds Logs Longer, Asks ISP"s to Correct Identification Mistakes — The RIAA has sent out a letter to ISP"s attempting to chang
>>Herding the Mob ... John and Nina Swanson run a business selling ... (Annalee Newitz/Wired News) #
    Herding the Mob … John and Nina Swanson run a business selling vintage postcards on eBay. To keep customers happy, the Swansons reply to buyers promptly and ship on time. This policy is refl
>>Viacom files $1 billion copyright infringement suit against Google #
    Viacom, the giant owner of video content, has sued YouTube and Google for “massive intentional copyright infringement” of Viacom’s properties. It is one of the biggest challenges yet to w
>>Tired of Your Yahoo Title and Description Showing up in Searches? #
    Web site owners that have listings in the Yahoo Directory (remember when Yahoo was a directory instead of a search engine?) have long lamented the fact that Yahoo liked to pull the directory listing d
>>Google Clarifies Some Webmaster Guidelines #
    Google has made some minor changes to its Webmaster guidelines, which appear to be aimed at clarifying policies rather than substantially changing them. The changes, as spotted by Philipp Lenssen, inc
>>Omidyar Network appoints new leader, to double in size #
    Omidyar Network, the organization created eBay founder Pierre Omidyar and his wife, Pam, has appointed a new leader to help expand the group. Matt Bannick, an executive at eBay for eight years, takes
>>Put Your Best Foot Forward: 19 Gorgeous Website Footers #
    Posted by OatmealFooters usually repeat the primary navigation and contain anything that is considered "the fine print," such as copyright information and a privacy policy. With the rising
>>Kleiner’s investment in oil exploration company, Terralliance #
    Turns out, Kleiner Perkins Caufield & Byers, the respected Silicon Valley venture firm that preached the need for a green-friendly investment and energy policy, has been secretly investing in an

Other Posts:
>>$150等于什么?
>>Gmail的小Bug
>>在MOSS中直接嵌入ASP.NET Page
>>2007 MVP Summit, MS Campus Day
>>Google也来凑热闹-网站导航
>>MSN客户端广告新形式
>>细微之处见功力-看看Gmail是怎么收取POP3邮件的
>>Orcas中C#语言的新特性:自动属性,对象初始化器,和集合初始化器
>>Visual Studio 2005 sp1 中Web Project和Web Site 项目开发站点的启动问题
>>通过实例分析WCF Duplex消息交换
>>这几天微软发布的一些好玩的东西
>>Scott Guthrie射击甜圈列兵的录像(以及一些好的ASP.NET AJAX链接)


Month Archives:

Top Tags:
Internet Technology Google Company & Product Profiles Search feature column letter analysis Search Headlines comment Startups WebApp咨询 互联网络 BigCos 业界信息 国际政治 业界动态 Google/SEO Search Types: Local 播客指南 news 抓虾动态 application Yahoo 搜索引擎 Yahoo: Search Ads Search Engines and Directories Web2.0 Link Building


@2007 All rights Reserved