11 Tool-based Aspect-Oriented Programming

 

In this chapter

  • Using dynamic Interception to apply Interceptors using generated Decorators
  • Advantages and disadvantages of dynamic Interception
  • Using compile-time weaving to apply Cross-Cutting Concerns
  • Why compile-time weaving is the antithesis of DI

This chapter is a continuation of the Aspect-Oriented Programming (AOP) discussion that we started in chapter 10. Where chapter 10 described AOP in its purest form—namely, applying AOP solely using SOLID design practices—this chapter approaches AOP from a tool-based perspective. We’ll discuss two common methods for applying AOP: dynamic Interception and compile-time weaving.

In case the design approach of chapter 10 is too radical, dynamic Interception will be your next best pick, which is why we’ll discuss it first. Dynamic Interception might be a good temporary solution until the right time arrives to start making the kinds of improvements discussed in the last chapter.

Compile-time weaving is the opposite of DI, and we consider it to be an anti-pattern. We feel it’s important, however, to include a discussion on compile-time weaving, because it’s a well-known form of AOP, and we want to make it clear that it isn’t a viable alternative to DI.

Tip

Our coverage of these tools is limited to the topic of DI. If you’re interested in learning more about tool-based AOP, there’s a book on this topic: AOP in .NET, by Matthew D. Groves (Manning, 2013).

11.1 Dynamic Interception

11.1.1 Example: Interception with Castle Dynamic Proxy

11.1.2 Analysis of dynamic Interception

11.2 Compile-time weaving

11.2.1 Example: Applying a transaction aspect using compile-time weaving

11.2.2 Analysis of compile-time weaving

Summary