Chapter 7. AOP implementation types

 

This chapter covers

  • How runtime weaving works
  • The difference between proxy and dynamic proxy
  • Defining a postcompiler
  • What postcompiled code looks like
  • The trade-offs between runtime and compile-time weaving

After reading this chapter, you might still not be able to implement your own AOP tool, but you should have a basic understanding of how the two main types of AOP tools work. These two main tools, which I’ve been using in this book, are PostSharp and Castle DynamicProxy.

PostSharp is a postcompiler that performs weaving at compile time; Castle DynamicProxy generates proxy classes at runtime. I’ve glossed over some of the details of how these tools work in favor of how to use them. But the more you use AOP tools in your code, the more important it is to know exactly how they work.

For the purposes of this chapter, PostSharp will be representing compile-time weaving and DynamicProxy will be representing runtime weaving. These tools are first-class representatives, and their implementations will teach you a lot about how AOP works.

7.1. How does AOP work?

Recall the figure from chapter 1 (repeated here in figure 7.1).

Figure 7.1. A high-level diagram of AOP

7.2. Runtime weaving

7.3. Compile-time weaving

7.4. Runtime versus compile-time weaving

7.5. Summary

sitemap