AspectInjector 2.8.2-pre1

.NET Standard 2.0
This is a prerelease version of AspectInjector.
dotnet add package AspectInjector --version 2.8.2-pre1
NuGet\Install-Package AspectInjector -Version 2.8.2-pre1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="AspectInjector" Version="2.8.2-pre1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add AspectInjector --version 2.8.2-pre1
#r "nuget: AspectInjector, 2.8.2-pre1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install AspectInjector as a Cake Addin
#addin nuget:?package=AspectInjector&version=2.8.2-pre1&prerelease

// Install AspectInjector as a Cake Tool
#tool nuget:?package=AspectInjector&version=2.8.2-pre1&prerelease


<h3><span style="color: #ff0000;"><strong>I have never asked for any donations, but today, I ask you, please, consider donating Ukrainian Army.<br /></strong></span></h3> <h3><span style="color: #ff0000;"><strong>You can find official ways to do it <a href="">here</a> or you can donate to the biggest charity organization <a href="">here</a></strong></span></h3> <h3><span style="color: #ff0000;"><strong>People need to be alive to create open source projects!</strong></span></h3>

<img src="" width="48" align="right"/>Aspect Injector

Aspect Injector is an attribute-based framework for creating and injecting aspects into your .net assemblies.

Project Status

Nuget Nuget Pre Nuget

GitHub (Pre-)Release Date GitHub last commit

Application Status Samples Status


> dotnet add package AspectInjector


  • Compile-time injection - works with Blazor and AOT
  • Injecting Before, After and Around (wrap) Methods, Constructors, Properties and Events
  • Injecting Interface implementations
  • Supports any project that can reference netstandard2.0 libraries, see here
  • Debugging support
  • Roslyn analyzers for your convenience (only c# currently)
  • Can work DI/IoC frameworks #166

Check out samples and docs


  • (semi-optional) Nuget 5.0+ for transient build feature. All modern versions of VS and dotnetsdk have it. (If you still use project.json for some reason - make sure you add AspectInjector to all projects in the solution)
  • (optional) For analyzers to work in VSCode, don't forget to enable "omnisharp.enableRoslynAnalyzers": true

Known Issues / Limitations

  • Unsafe methods are not supported and are silently ignored.

Simple advice

Create an aspect with simple advice:
public class LogCall : Attribute
    [Advice(Kind.Before)] // you can have also After (async-aware), and Around(Wrap/Instead) kinds
    public void LogEnter([Argument(Source.Name)] string name)
        Console.WriteLine($"Calling '{name}' method...");   //you can debug it	
Use it:
public void Calculate() 

$ dotnet run
Calling 'Calculate' method...

Simple mixin

Create an aspect with mixin:
public interface IInitializable
    void Init();

public class Initializable : IInitializable, Attribute
    public void Init()
Use it:
public class Target

var target = new Target() as IInitializable;
$ dotnet run
Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net461 net462 net463 net47 net471 net472 net48 net481
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages (35)

Showing the top 5 NuGet packages that depend on AspectInjector:

Package Downloads

NUnit attributes extenstions for Allure




Steps Attribute for NUnit.Allure


Package Description


This package provides cache aspect for your methods. Put [MemoryCache(seconds)] attribure on your methods. And enjoy hassle-free memory cache for your methods. Or implement your own cache mechanics by inheriting CacheAttribute class. Powered by AspectInjector.

GitHub repositories (3)

Showing the top 3 popular GitHub repositories that depend on AspectInjector:

Repository Stars
Blazor Boilerplate / Starter Template with MudBlazor
AOP framework for .NET (c#, vb, etc)
The JHRS WPF framework is used to demonstrate how to use wpf and xamarin to build a development framework. The presentation framework only provides an idea. If you apply it to actual projects, you need to complete more functions yourself.
Version Downloads Last updated
2.8.2-pre1 6,657 2/1/2023
2.8.1 54,082 11/14/2022
2.8.0 48,854 9/22/2022
2.7.5-pre2 7,559 7/28/2022
2.7.5-pre1 148 7/27/2022
2.7.4 48,725 7/22/2022
2.7.4-pre1 146 7/20/2022
2.7.3 23,084 6/20/2022
2.7.3-pre1 239 4/7/2022
2.7.2 208,675 1/24/2022
2.7.1 782 1/22/2022
2.6.1 36,286 12/7/2021
2.6.0 503,012 8/23/2021
2.5.0 237,753 3/8/2021
2.4.4 12,437 1/28/2021
2.4.3 4,677 12/30/2020
2.4.1 142,977 7/31/2020
2.4.0 30,970 6/17/2020
2.3.1 111,781 2/18/2020
2.3.0 22,102 2/10/2020
2.2.8 7,847 1/19/2020
2.2.5 9,931 10/14/2019
2.2.4 5,485 10/11/2019
2.2.1 34,178 6/16/2019
2.1.1 24,944 5/3/2019
2.1.0 3,294 4/17/2019
2.0.6 2,599 2/11/2019
2.0.2 4,181 1/3/2019
1.0.2 5,522 4/26/2019
1.0.1 15,705 4/2/2018
0.9.44 3,406 8/5/2015
0.9.43 1,765 8/4/2015
0.9.42 1,845 8/4/2015