Policy Injection Application Block and CachingCallHandler - Great Use of Aspect Oriented Programming
by David Hayden ( Microsoft MVP C# ), Filed: Enterprise Library 3.0
Call me crazy, but I think the CachingCallHandler we are going to see in the final release of Enterprise Library 3.0 is a great use of Aspect-Oriented Programming. I love the idea of declaratively specifying caching using the [CachingCallHandler] Attribute as shown below:
public class NewsController
{
private INewsService _service;
public NewsController(INewsService service)
{
_service = service;
}
[CachingCallHandler]
public NewsHeadlineCollection GetLatestNewsHeadlines()
{
return _service.GetLatestNews();
}
}
The CachingCallHandler will intercept the GetLatestNewsHeadlines() method before it is called to see if the Latest News Headlines are already in the Cache. If they are, it returns the results in the cache instead of calling the method. This saves us a potentially expensive call to a database.
If there is nothing in the cache, the method is called and the CachingCallHandler intercepts the method after it is called and puts the results in the cache. This way we can avoid the expensive database call on further calls to the method.
All of this is being done behind the scenes without you having to write a single line of code. Of course, if you don't want to use the attribute, you can configure a policy in the configuration file. We won't see this until Enterprise Library 3.0 is released, which I expect to be any day now.
Policy Injection Application Block Tutorials
More Policy Injection Application Block Tutorials:
Source: David Hayden ( Sarasota Web Design )
Filed: Enterprise Library 3.0