Skip to content
AOP framework for .NET (c#, vb, etc)
Branch: master
Clone or download
pamidur Merge pull request #96 from Three97/three97-docupdate
Minor updates to documentation.
Latest commit 4929d5b Jun 17, 2019

README.md

Aspect Injector

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

Project Status

NuGet NuGet Pre Release Build Status

Download

> dotnet add package AspectInjector

Features

  • Compile-time injection
  • Injecting Before, After and Around targets
  • Injecting into Methods, Properties, Events
  • Injecting Interface implementaions
  • Supports any project that can reference netstandard2.0 libraries
  • Debugging support
  • Roslyn analyzers for your convenience (only c# currently)

Check out samples and docs

Requirements

  • .NetCore runtime 2.1.6+

Known Issues / Limitations

  • If you use Visual Studio earlier than 2019 you'll need to reference AspectInjector in every project when you want your injections to work. Since VS2019 it is fixed. On your build environments it is enough to use at least .NetCoreSDK 2.1.602 and dotnet build command.
  • Unsafe methods are not supported and are silently ignored.
  • You cannot inject code around constructors. Such attempts are silently ignored. You can since 2.2.1!

Trivia

Create aspect:

[Aspect(Scope.Global)]
[Injection(typeof(LogCall))]
class LogCall : Attribute
{
    [Advice(Kind.Before)]
    public void LogEnter([Argument(Source.Name)] string name)
    {
        Console.WriteLine($"Calling {name}");   //you can debug it	
    }
}

Use it:

[LogCall]
public void Calculate() { }
You can’t perform that action at this time.