Chapter 4. Before and after: boundary aspects
This chapter covers
- What boundaries mean
- Using PostSharp to bound methods
- Writing an ASP.NET HttpModule to help detect mobile users
- The differences (and similarities) of method interception and method bounding
- Writing a caching aspect with PostSharp
In chapter 3, I covered one of the most common types of method aspects you can write: method interception. These aspects contain code that runs instead of the code that it intercepts.
Another type of aspect you might use is a boundary aspect, which contains code that runs around the code that it’s bounding. (Most commonly, these aspects are methods, but other types of boundaries exist, including page requests, ASP.NET MVC controller actions, and entire programs.)
I’ll be using PostSharp to demonstrate a boundary aspect at the method level. I’ll also use something that might be familiar already—an ASP.NET HttpModule—to demonstrate a boundary aspect at the page level.
The point of this chapter isn’t to teach you everything about PostSharp and ASP.NET’s HttpModule but to show you what’s meant by the term boundary and how boundary aspects work in general. At the end of this chapter, you’ll know how to write boundary aspects, you’ll have a couple of practical aspects for caching, and mobile browser detection.