Policy Injection Application Block Validation and Logging Examples - Aspect Oriented Programming in Enterprise Library 3.0

 

This good article comes from : http://davidhayden.com/blog/dave/archive/2007/03/25/PolicyInjectionApplicationBlockOrlandoCodeCamp.aspx,

where we can get lots of papers.

 

I had a blast presenting at the Orlando Code Camp this weekend. One of my presentations, Enterprise Library 3.0 – New and Improved!, discussed several topics, but focused on the new Validation Application Block and Policy Injection Application Block. The Policy Injection Application Block is a difficult topic to Grok in 20 minutes at a Code Camp, especially since it will not be complete and have configuration editor support until the final release of Enterprise Library v3.0 during the 1st week of April 2007.

You can read two of my tutorials on the Policy Injection Application Block here for additional information:

 

Both of the tutorials mentioned above use the TagAttributeMatchingRule to specify methods that will be intercepted by the Policy Injection Application Block. The TagAttributeMatchingRule looks like the following:

 

public interface IOrder
{
    [Tag("Log")]
    void Return(string reason);
}

 

However, the TagAttributeMatchingRule is not the only way to specify type methods to intercept. Based on the Februrary 2007 CTP you have the following Matching Rules and I have really only discussed one:

 

Policy Injection Application Block Matching Rules

 

In an example I provided at the Orlando Code Camp and that is available for download, I used two other Matching Rules:

  • TypeMatchingRule
  • MemberNameMatchingRule

 

Used together these two rules can also specify the Return Method on the IOrder Interface without requiring any attributes be added:

 

public interface IOrder
{
    void Return(string reason);
}


<policies>
    <add name="Logging">
        <matchingRules>
            <add
                type="...TypeMatchingRule..."
                name="Type Matching Rule"
                match="IOrder"
                ignoreCase="false" />
            <add
                type="....MemberNameMatchingRule..."
                name="Member Matching Rule"
                match="Return"
                ignoreCase="false" />
        </matchingRules>
        <handlers>
            <add
                name="Logging Handler"
                type="...LogCallHandler..."
                logBehavior="Before"
                beforeMessage="Logging Return..."
                includeParameterValues="true"
                includeCallTime="true"
                includeCallStack="false"
                severity="Information">
                    <categories>
                        <add name="General" />
                    </categories>
            </add>
        </handlers>
    </add>
</policies>

 

Now when you use the Policy Injection Application Block as follows:

 

IOrder order =
PolicyInjection.Create<Order, IOrder>(); order.Return("No change in size.");

 

The Policy Injection Application Block will log the reason for the order being returned before executing the Return Method. One could have also specified that the logging occur after the execution of the Return Method instead.

 

Timestamp: 3/25/2007 2:14:17 PM
Message: Logging Return
Category: General
Priority: 0
EventId: 1
Severity: Information
Extended Properties: reason - No change in size.

 

Conclusion

It will be easier to work with the Policy Injection Application Block once we can use the Enterprise Library Configuration Editor to configure it properly. This will happen when it is released during the first week of April 2007.

Source: David Hayden ( Florida ASP.NET Developer )

Filed: Enterprise Library 3.0

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值