Question

2 Questions:

  1. Are Action Filters in MVC considered Aspect Oriented Programming (AOP)?
  2. If so, does .NET provide something similar for non MVC code (i.e. regular class library?)

The context is I want to add logging to a application. Instead of sprinkling logging code all over the place, I like the idea of being able to define rules for logging in one central location.

It seems that I can achieve this using an AOP technology (PostSharp). However, if there is something build in to .NET I would probably end up using that.

Was it helpful?

Solution

Generally, AOP is a programming paradigm and has nothing to do with specific technologies like MVC or PostSharp in the first place. This said: Yes, Action Filters are an incarnation of this paradigm.

In plain .NET, AOP can be done by using custom attributes and reflection (meaning that the entire work is done at runtime). PostSharp on the contrary is an aspect weaver and does its magic at compile time, modifying the IL output of the C# compiler. Therefore, no runtime performance penalty whatsoever will be involved. Moreover, PostSharp has many things (like e.g. logging) pre-built out of the box, and it is much more type-safe and very extensible.

You can use plain .NET. But this would be the same as preferring a stagecoach over a racing car.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top