concept aspect in category .net

appears as: An aspect, n aspect, The aspect, aspect, spects, spect, aspects, The aspects
AOP in .NET

This is an excerpt from Manning's book AOP in .NET.

Once you’ve identified the what (advice) and the where (join points/pointcuts), you can define an aspect. The aspect works through a process known as weaving.

It’s time to clean up this mess. When refactoring, you should always have unit tests in place so you know that your refactoring didn’t cause any regressions, but because this example is relatively small and contrived, I’ve left them as an exercise for the reader. (I’ve always wanted to write that.) But don’t worry: chapter 6 is devoted to the topic of unit testing and aspects.

Listing 2.27. All cross-cutting concerns refactored into aspects
Listing 2.25. Continuing to refactor with aspects
[DefensiveProgramming] [LoggingAspect] [TransactionManagement] public void Accrue(RentalAgreement agreement) { // ... snip ... } [DefensiveProgramming] [LoggingAspect] [TransactionManagement] public void Redeem(Invoice invoice, int numberOfDays) { // ... snip ... }
Dependency Injection in .NET

This is an excerpt from Manning's book Dependency Injection in .NET.

Figure 9.1. The overall structure of this chapter is pretty linear. We’ll start with an introduction to INTERCEPTION, including an example. From there we move on to talk about CROSS-CUTTING CONCERNS. This section of the chapter is light on theory and heavy on examples, so if you’re already familiar with this subject, you can consider moving directly to the last section, about aspects. This section serves as the climax of the chapter as it introduces the advanced yet versatile concept of dynamic INTERCEPTION.

It sounds attractive to extrapolate this concept to other CROSS-CUTTING CONCERNS. Wouldn’t it be nice if you could decorate a method or class with a [HandleError] attribute, or even a custom [CircuitBreaker] attribute, and, in this way, apply the aspect with a single line of declarative code?

Figure 9.8. PostSharp works by adding a post-compilation step after normal compilation has completed. Because the custom PostSharp attributes on your code are treated no differently than any other attribute by the normal compiler (for example, csc.exe), the output is a normal assembly with passive attributes. PostSharp includes a post-compilation step where PostSharp picks up the compiled assembly and interleaves the code from your custom attributes directly into the attributed code. The result is a new .NET assembly with the aspects embedded.