[Home](../../) › [Metalama](../../metalama) › [Use Cases](../applications.md) › [Alternatives](../alternatives.md) › Alternatives for AOP

# Alternatives for AOP

> The document compares aspect-oriented programming frameworks for .NET, detailing approaches like MSIL rewriting, Roslyn-based, and middleware.

Canonical: https://postsharp.net/metalama/alternatives/aspect-oriented-programming.html

Today's aspect-oriented frameworks all rely on one of the following approaches:

* [MSIL Rewriting](https://postsharp.net/metalama/alternatives/msil-rewriting) is the process of modifying the binary assembly during the build process. An additional step is added to this process just after the C# compiler. This approach was pioneered by PostSharp when the C# compiler was a black box. Many tools still rely on it.

* **Roslyn-based** frameworks interact directly with the compiler without requiring an additional process. They are based on official Roslyn extension points such as analyzers and code generators, plus unofficial extension points added by [Metalama.Compiler](https://github.com/metalama/Metalama.Compiler), an open-source fork of Roslyn, allowing arbitrary code transformations. [Metalama](https://postsharp.net/metalama) is the only framework in this category at the moment. Roslyn-based frameworks can give you real-time feedback as you are typing, while MSIL-based ones require you to rebuild.

* [Middleware-based frameworks](https://postsharp.net/metalama/alternatives/middleware) generally rely on a dependency injection framework and generate dynamic proxies at runtime. They are limited to intercepting interface methods and adding new interfaces to types.

Here is an overview of the main aspect-oriented frameworks available for .NET. This list is followed by a table comparing their features.

## PostSharp

[PostSharp](https://postsharp.net/postsharp), developed since 2004, was the first complete implementation of AOP concepts in .NET. It is based on [MSIL rewriting](https://postsharp.net/metalama/alternatives/msil-rewriting). PostSharp became a source of inspiration for several MSIL-based AOP frameworks.

PostSharp includes a broad set of ready-made aspects. It has complete documentation.

It comes with a Visual Studio extension that provides visibility into the transformations performed by aspects.

## Metalama

[Metalama](https://postsharp.net/metalama), PostSharp's open-source patterns & architecture toolkit for C#, was first released in 2023. Based on Roslyn, Metalama works both at design time (within the IDE) and at compile time. It is the most complete implementation of aspect-oriented principles, as the comparison table below shows.

Metalama uses a C#-to-C# template language coined _T#_. T# is 100% C#-compatible, so you can get full IntelliSense support with any IDE.

Since Metalama generates C# and not MSIL, you can preview and even debug the code generated by your aspects.

Metalama shares the same Visual Studio extension as PostSharp.

## AspectInjector

Like PostSharp, [AspectInjector](https://github.com/pamidur/aspect-injector) is based on [MSIL rewriting](https://postsharp.net/metalama/alternatives/msil-rewriting).

While far from PostSharp in terms of features, AspectInjector supports most code overriding and introduction features expected from an AOP framework.

## Rougamo

[Rougamo](https://github.com/inversionhourglass/Rougamo) is another compile-time AOP framework based on [MSIL rewriting](https://postsharp.net/metalama/alternatives/msil-rewriting). Its code transformation abilities are limited. It implements an AspectJ-inspired pointcut mechanism to select code to be modified.

## AspectCore

[AspectCore](https://github.com/dotnetcore/AspectCore-Framework) is an aspect-oriented framework based on [dynamic proxies](https://postsharp.net/metalama/alternatives/middleware). This approach operates at runtime by generating a _proxy_ type between the consumer and the implementation of an interface. It works only with components served by a dependency injection framework.

## Fody

[Fody](https://github.com/Fody/Fody) is an extensible tool for weaving .NET assemblies. While it is not an aspect framework in itself, [some](https://github.com/vescon/MethodBoundaryAspect.Fody) [plug-ins](https://github.com/Fody/MethodDecorator) allow for PostSharp-style decoration of methods, enabling the implementation of some simple aspects.

Fody has a long list of [plug-ins](https://github.com/Fody/Home/blob/master/pages/addins.md) that implement specific code transformations. Because these transformations must be coded directly in MSIL and not in C#, Fody does not fully qualify as an aspect-oriented framework.

## Comparison

|                                               | Metalama | PostSharp | AspectInjector | Rougamo | AspectCore      |
|-----------------------------------------------|----------|-----------|----------------|---------|-----------------|
| Technology                                    | Roslyn   | MSIL      | MSIL           | MSIL    | Dynamic Proxies |
| Override virtual members                      | Yes      | Yes       | Yes            | Yes     | Yes             |
| Override non-virtual members                  | Yes      | Yes       | Yes            | Yes     | No              |
| Implement interfaces                          | Yes      | Yes       | Yes            | No      | Yes             |
| Introduce new members                         | Yes      | Yes       | Yes            | No      | No              |
| Reference introduced members from source code | Yes      | No        | No             | No      | No              |
| Allocationless context passing                | Yes      | No        | Yes            | No      | No              |
| IDE: Aspect Explorer                          | Yes      | Yes       | No             | No      | No              |
| IDE: CodeLens                                 | Yes      | Yes       | No             | No      | No              |
| View/Debug Generated C#                       | Yes      | No        | No             | No      | No              |
| Large library of pre-built aspects            | Yes      | Yes       | No             | No      | No              |

---

## Site navigation

- Next: [Code Generation](code-generation.md)
- Index of the whole site: [llms.txt](../../llms.txt)

