AspectInjector 2.9.0
dotnet add package AspectInjector --version 2.9.0
NuGet\Install-Package AspectInjector -Version 2.9.0
<PackageReference Include="AspectInjector" Version="2.9.0" />
<PackageVersion Include="AspectInjector" Version="2.9.0" />
<PackageReference Include="AspectInjector" />
paket add AspectInjector --version 2.9.0
#r "nuget: AspectInjector, 2.9.0"
#:package AspectInjector@2.9.0
#addin nuget:?package=AspectInjector&version=2.9.0
#tool nuget:?package=AspectInjector&version=2.9.0

<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="https://bank.gov.ua/en/news/all/natsionalniy-bank-vidkriv-spetsrahunok-dlya-zboru-koshtiv-na-potrebi-armiyi">here</a> or you can donate to the biggest charity organization <a href="https://www.comebackalive.in.ua/">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="https://raw.githubusercontent.com/pamidur/aspect-injector/master/package.png" width="48" align="right"/>Aspect Injector
Aspect Injector is an attribute-based framework for creating and injecting aspects into your .net assemblies.
Project 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)
- Can work DI/IoC frameworks #166
Requirements
- (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:
[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!
| Product | Versions Compatible and additional computed target framework versions. | 
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. | 
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. | 
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. | 
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. | 
| MonoAndroid | monoandroid was computed. | 
| MonoMac | monomac was computed. | 
| MonoTouch | monotouch was computed. | 
| Tizen | tizen40 was computed. tizen60 was computed. | 
| Xamarin.iOS | xamarinios was computed. | 
| Xamarin.Mac | xamarinmac was computed. | 
| Xamarin.TVOS | xamarintvos was computed. | 
| Xamarin.WatchOS | xamarinwatchos was computed. | 
- 
                                                    .NETStandard 2.0- No dependencies.
 
NuGet packages (70)
Showing the top 5 NuGet packages that depend on AspectInjector:
| Package | Downloads | 
|---|---|
| Allure.Net.Commons Provides common facilities to build Allure adapters for .NET test frameworks. | |
| NUnit.Allure NUnit attributes extenstions for Allure | |
| AWS.Lambda.Powertools.Logging Powertools for AWS Lambda (.NET) - Logging package. | |
| AWS.Lambda.Powertools.Tracing Powertools for AWS Lambda (.NET) - Tracing package. | |
| AWS.Lambda.Powertools.Metrics Powertools for AWS Lambda (.NET) - Metrics package. | 
GitHub repositories (6)
Showing the top 6 popular GitHub repositories that depend on AspectInjector:
| Repository | Stars | 
|---|---|
| enkodellc/blazorboilerplate 
                                                            Blazor Boilerplate / Starter Template with MudBlazor 
                                                         | |
| carlreid/StreamMaster 
                                                            A powerful M3U proxy and stream management platform for Plex DVR, Emby, Jellyfin Live TV (and more)
                                                         | |
| jhrscom/JHRS 
                                                            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.
                                                         | |
| aws-powertools/powertools-lambda-dotnet 
                                                            Powertools is a developer toolkit to implement Serverless best practices and increase developer velocity.
                                                         | |
| allure-framework/allure-csharp 
                                                            Allure integrations for C# test frameworks
                                                         | |
| m969/AOGame 
                                                            A game framework base on ETCore.
                                                         | 
| Version | Downloads | Last Updated | |
|---|---|---|---|
| 2.9.0 | 18,045 | 9/13/2025 | |
| 2.9.0-pre4 | 321 | 9/13/2025 | |
| 2.9.0-pre3 | 93 | 9/13/2025 | |
| 2.9.0-pre2 | 97 | 9/13/2025 | |
| 2.9.0-pre1 | 713 | 9/25/2024 | |
| 2.8.3-pre3 | 25,119 | 10/6/2023 | |
| 2.8.3-pre2 | 4,911 | 8/24/2023 | |
| 2.8.3-pre1 | 2,160 | 7/14/2023 | |
| 2.8.2 | 1,019,300 | 7/5/2023 | |
| 2.8.2-pre3 | 1,800 | 6/9/2023 | |
| 2.8.2-pre2 | 1,474 | 6/8/2023 | |
| 2.8.2-pre1 | 264,765 | 2/1/2023 | |
| 2.8.1 | 4,725,728 | 11/14/2022 | |
| 2.8.0 | 146,732 | 9/22/2022 | |
| 2.7.4 | 138,700 | 7/22/2022 | |
| 2.7.3 | 109,666 | 6/20/2022 | |
| 2.7.2 | 391,362 | 1/24/2022 | |
| 2.6.1 | 60,505 | 12/7/2021 | |
| 2.6.0 | 1,649,099 | 8/23/2021 | |
| 2.5.0 | 355,995 | 3/8/2021 | |
| 2.4.4 | 16,580 | 1/28/2021 | |
| 2.4.3 | 6,684 | 12/30/2020 | |
| 2.4.1 | 190,709 | 7/31/2020 | |
| 2.4.0 | 58,635 | 6/17/2020 | |
| 2.3.1 | 302,343 | 2/18/2020 | |
| 2.3.0 | 24,197 | 2/10/2020 | |
| 2.2.8 | 9,824 | 1/19/2020 | |
| 2.2.5 | 12,299 | 10/14/2019 | |
| 2.2.4 | 6,861 | 10/11/2019 | |
| 2.2.1 | 38,079 | 6/16/2019 | |
| 2.1.1 | 26,457 | 5/3/2019 | |
| 2.1.0 | 4,678 | 4/17/2019 | |
| 2.0.6 | 4,032 | 2/11/2019 | |
| 2.0.2 | 5,599 | 1/3/2019 | |
| 1.0.2 | 8,939 | 4/26/2019 | |
| 1.0.1 | 17,509 | 4/2/2018 | |
| 0.9.44 | 5,144 | 8/5/2015 | |
| 0.9.43 | 3,175 | 8/4/2015 | |
| 0.9.42 | 3,228 | 8/4/2015 |