AspectInjector 2.6.1

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
AWS.Lambda.Powertools.Logging
Powertools for AWS Lambda (.NET) - Logging package.
32
AWS.Lambda.Powertools.Logging
Powertools for AWS Lambda (.NET) - Logging package.
24
AWS.Lambda.Powertools.Common
Powertools for AWS Lambda (.NET) - Core package.
23
AWS.Lambda.Powertools.Logging
Powertools for AWS Lambda (.NET) - Logging package.
23
AWS.Lambda.Powertools.Logging
Powertools for AWS Lambda (.NET) - Logging package.
21
AWS.Lambda.Powertools.Logging
Powertools for AWS Lambda (.NET) - Logging package.
20
AWS.Lambda.Powertools.Logging
Powertools for AWS Lambda (.NET) - Logging package.
19
AWS.Lambda.Powertools.Common
AWS Lambda Powertools for .NET - Core package.
19
AWS.Lambda.Powertools.Logging
Powertools for AWS Lambda (.NET) - Logging package.
18
AWS.Lambda.Powertools.Common
Powertools for AWS Lambda (.NET) - Core package.
17
AWS.Lambda.Powertools.Logging
Powertools for AWS Lambda (.NET) - Logging package.
17
AWS.Lambda.Powertools.Common
AWS Lambda Powertools for .NET - Core package.
15
AWS.Lambda.Powertools.Logging
Powertools for AWS Lambda (.NET) - Logging package.
15

.NET Standard 2.0

  • No dependencies.

Version Downloads Last updated
2.9.0 60 10/14/2025
2.9.0-pre4 24 06/20/2026
2.9.0-pre3 26 06/28/2026
2.9.0-pre2 20 06/24/2026
2.9.0-pre1 25 10/03/2024
2.8.3-pre3 33 01/08/2024
2.8.3-pre2 27 01/08/2024
2.8.3-pre1 17 01/08/2024
2.8.2 35 01/07/2024
2.8.2-pre3 33 01/08/2024
2.8.2-pre2 24 01/08/2024
2.8.2-pre1 31 01/08/2024
2.8.1 29 01/07/2024
2.8.0 31 01/07/2024
2.7.4 24 01/07/2024
2.7.3 32 01/06/2024
2.7.2 37 01/06/2024
2.6.1 28 01/07/2024
2.6.0 23 01/07/2024
2.5.0 34 01/07/2024
2.4.4 48 01/07/2024
2.4.3 24 01/07/2024
2.4.1 26 01/07/2024
2.4.0 31 01/07/2024
2.3.1 30 01/07/2024
2.3.0 28 01/05/2024
2.2.8 24 01/07/2024
2.2.5 37 01/07/2024
2.2.4 30 01/07/2024
2.2.1 32 01/07/2024
2.1.1 38 01/07/2024
2.1.0 29 01/07/2024
2.0.6 20 01/07/2024
2.0.2 22 01/07/2024
1.0.2 26 01/11/2024
1.0.1 26 01/07/2024
0.9.44 29 01/06/2024
0.9.43 28 01/07/2024
0.9.42 23 01/07/2024