Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
A

aspect-injector

> 编程语言
Open source

AOP framework for .NET (c#, vb, etc)

829 stars0 likes0 views
WebsiteGitHub

About

AOP framework for .NET (c#, vb, etc)

I have never asked for any donations, but today, I ask you, please, consider donating Ukrainian Army.

You can find official ways to do it here or you can donate to the biggest charity organization here

People need to be alive to create open source projects!





Aspect Injector

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

Project Status

Download

bash
> 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

Check out samples and docs

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:

csharp
[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:

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

Calculate();

Result:

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

Simple mixin

Create an aspect with mixin:

csharp
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:

csharp
[Initializable]
public class Target
{ 
}

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

Result:

bash
$ dotnet run
Initialized!

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

C#adviceaopaop-frameworkaot

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言