AspectInjector 2.7.0

Aspect Injector

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

Project Status

Nuget Nuget Pre GitHub (Pre-)Release Date GitHub last commit

Application Status Samples Status

Download

> dotnet add package AspectInjector

Features

  • 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)

Check out samples and docs

Requirements

  • .NetCore runtime 2.1.6+ installed on your machine (your projects can be anything that can reference netstandard2.0)
  • (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

  • 'Edit and Continue' feature in VS is not working at the moment with .netcore3+ #138
  • Unsafe methods are not supported and are silently ignored.

Simple advice

Create an aspect with simple advice:

[Aspect(Scope.Global)]
[Injection(typeof(LogCall))]
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:

[LogCall]
public void Calculate() 
{ 
    Console.WriteLine("Calculated");
}

Calculate();

Result:

$ dotnet run
Calling 'Calculate' method...
Calculated

Simple mixin

Create an aspect with mixin:

public interface IInitializable
{
    void Init();
}

[Aspect(Scope.PerInstance)]
[Injection(typeof(Initializable))]
[Mixin(typeof(IInitializable))]
public class Initializable : IInitializable, Attribute
{
    public void Init()
    {
        Console.WriteLine("Initialized!");
    }
}

Use it:

[Initializable]
public class Target
{ 
}

var target = new Target() as IInitializable;
target.Init();

Result:

$ dotnet run
Initialized!

Showing the top 20 packages that depend on AspectInjector.

Packages Downloads
Allure.Net.Commons
Provides common facilities to build Allure adapters for .NET test frameworks.
8
Allure.Net.Commons
Provides common facilities to build Allure adapters for .NET test frameworks.
7
Allure.Net.Commons
Provides common facilities to build allure integrations for .NET test frameworks
5
Allure.Net.Commons
Provides common facilities to build Allure adapters for .NET test frameworks.
5
Allure.XUnit
Allure.XUnit
4
Allure.Net.Commons
Provides common facilities to build Allure adapters for .NET test frameworks.
4
Allure.Net.Commons
Provides common facilities to build allure integrations for .NET test frameworks
4
Allure.XUnit
Allure.XUnit
3

.NET Standard 2.0

  • No dependencies.

Version Downloads Last updated
2.9.0 12 03/16/2026
2.9.0-pre4 6 03/30/2026
2.9.0-pre3 4 04/25/2026
2.9.0-pre2 4 04/25/2026
2.9.0-pre1 4 04/25/2026
2.8.3-pre3 6 03/30/2026
2.8.3-pre2 4 04/25/2026
2.8.3-pre1 3 04/25/2026
2.8.2 3 04/24/2026
2.8.2-pre3 4 04/25/2026
2.8.2-pre2 6 03/30/2026
2.8.2-pre1 5 03/30/2026
2.8.1 6 03/21/2026
2.8.0 4 03/30/2026
2.7.5-pre2 4 04/30/2026
2.7.5-pre1 4 04/30/2026
2.7.4 3 04/24/2026
2.7.4-pre1 4 04/30/2026
2.7.3 4 04/24/2026
2.7.3-pre1 4 04/30/2026
2.7.2 5 03/30/2026
2.7.1 4 04/30/2026
2.7.0 3 04/30/2026
2.6.1 3 04/24/2026
2.6.1-pre1 3 04/30/2026
2.6.0 4 04/24/2026
2.6.0-pre1 4 04/30/2026
2.5.1-pre2 3 04/30/2026
2.5.1-pre1 4 04/30/2026
2.5.0 4 04/24/2026
2.5.0-pre1 3 04/30/2026
2.4.4 5 03/30/2026
2.4.4-pre5 4 04/30/2026
2.4.4-pre4 4 04/30/2026
2.4.4-pre1 4 04/30/2026
2.4.3 3 04/24/2026
2.4.2 3 04/30/2026
2.4.1 4 04/24/2026
2.4.0 4 04/24/2026
2.4.0-beta1 4 04/30/2026
2.3.1 3 04/24/2026
2.3.0 3 04/24/2026
2.2.8 4 04/24/2026
2.2.7 3 04/30/2026
2.2.6 3 04/30/2026
2.2.5 4 04/24/2026
2.2.4 3 04/24/2026
2.2.3 3 04/30/2026
2.2.2 3 04/30/2026
2.2.1 3 04/24/2026
2.2.0 3 04/30/2026
2.1.1 3 04/24/2026
2.1.0 3 04/24/2026
2.0.6 4 04/24/2026
2.0.5 4 04/30/2026
2.0.4 4 04/30/2026
2.0.3 3 04/30/2026
2.0.2 3 04/24/2026
2.0.1 4 04/30/2026
2.0.0 3 04/30/2026
2.0.0-rc3 4 04/30/2026
2.0.0-rc2 4 04/30/2026
2.0.0-rc 4 04/30/2026
2.0.0-beta2 4 04/30/2026
2.0.0-beta1 5 04/30/2026
1.5.2-beta 4 04/30/2026
1.5.1-beta 3 04/30/2026
1.5.0-beta 4 04/30/2026
1.0.2 3 04/24/2026
1.0.2-pre 3 04/30/2026
1.0.1 3 04/24/2026
1.0.0 4 04/30/2026
1.0.0-rc5 4 04/30/2026
1.0.0-rc3 4 04/30/2026
1.0.0-rc2 5 04/30/2026
1.0.0-rc1 4 04/30/2026
1.0.0-beta4 4 04/30/2026
1.0.0-beta3 4 04/30/2026
1.0.0-beta2 4 04/30/2026
1.0.0-beta1 4 04/30/2026
0.9.44 4 04/25/2026
0.9.43 5 03/30/2026
0.9.42 5 03/30/2026
0.9.41 4 04/30/2026
0.9.40 4 04/30/2026
0.9.31 4 04/30/2026
0.9.30 4 04/30/2026
0.9.21 4 04/30/2026
0.9.4 3 04/30/2026
0.9.2 3 04/30/2026
0.9.1 3 04/30/2026
0.9.0 3 04/30/2026
0.8.47 4 04/30/2026
0.7.46 4 04/30/2026
0.5.44 4 04/30/2026
0.3.43 4 04/30/2026
0.2.42 4 04/30/2026
0.2.41 4 04/30/2026
0.1.40 4 04/30/2026