AspectInjector 2.6.1-pre1

This is a prerelease version of AspectInjector.
Install-Package AspectInjector -Version 2.6.1-pre1
dotnet add package AspectInjector --version 2.6.1-pre1
<PackageReference Include="AspectInjector" Version="2.6.1-pre1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add AspectInjector --version 2.6.1-pre1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: AspectInjector, 2.6.1-pre1"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install AspectInjector as a Cake Addin
#addin nuget:?package=AspectInjector&version=2.6.1-pre1&prerelease

// Install AspectInjector as a Cake Tool
#tool nuget:?package=AspectInjector&version=2.6.1-pre1&prerelease
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

<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

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!
  • .NETStandard 2.0

    • No dependencies.

NuGet packages (24)

Showing the top 5 NuGet packages that depend on AspectInjector:

Package Downloads
NUnit.Allure

NUnit attributes extenstions for Allure

NUnit.Allure.Steps

Steps Attribute for NUnit.Allure

NUnit.OneTimeSetup.DreddLogs

Helper library for NUnit that allows you to show all the logs that happened during test fixture setup (OneTimeSetup)

Flashcom.Util

常用调用类

Aspects.Cache

This package provides cache aspect for your methods. Put [MemoryCache(seconds)] attribure on your methods. And enjoy hassle-free memory cache for your methods. Or implement your own cache mechanics by inheriting CacheAttribute class. Powered by AspectInjector.

GitHub repositories (3)

Showing the top 3 popular GitHub repositories that depend on AspectInjector:

Repository Stars
enkodellc/blazorboilerplate
Blazor Boilerplate / Starter Template with MatBlazor
pamidur/aspect-injector
AOP framework for .NET (c#, vb, etc)
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.
Version Downloads Last updated
2.6.1-pre1 114 10/18/2021
2.6.0 30,222 8/23/2021
2.6.0-pre1 1,330 6/11/2021
2.5.1-pre2 124 5/29/2021
2.5.1-pre1 4,726 3/30/2021
2.5.0 99,103 3/8/2021
2.5.0-pre1 280 2/1/2021
2.4.4 10,088 1/28/2021
2.4.4-pre5 154 1/22/2021
2.4.4-pre4 161 1/21/2021
2.4.4-pre1 144 12/30/2020
2.4.3 3,102 12/30/2020
2.4.2 574 12/25/2020
2.4.1 84,206 7/31/2020
2.4.0 17,799 6/17/2020
2.4.0-beta1 281 4/30/2020
2.3.1 62,225 2/18/2020
2.3.0 14,324 2/10/2020
2.2.8 5,943 1/19/2020
2.2.7 335 1/18/2020
2.2.6 493 1/17/2020
2.2.5 7,833 10/14/2019
2.2.4 4,938 10/11/2019
2.2.3 410 10/9/2019
2.2.2 1,233 10/4/2019
2.2.1 31,057 6/16/2019
2.1.1 24,244 5/3/2019
2.1.0 2,765 4/17/2019
2.0.6 2,032 2/11/2019
2.0.5 527 2/7/2019
2.0.4 545 2/7/2019
2.0.3 533 2/7/2019
2.0.2 3,631 1/3/2019
2.0.1 603 1/3/2019
2.0.0 772 12/8/2018
2.0.0-rc3 613 12/8/2018
2.0.0-rc2 502 12/7/2018
2.0.0-rc 575 12/7/2018
2.0.0-beta2 569 12/7/2018
2.0.0-beta1 484 12/4/2018
1.0.2 2,128 4/26/2019
1.0.2-pre 495 4/23/2019
1.0.1 14,991 4/2/2018
1.0.0-rc2 1,052 7/14/2017
1.0.0-rc1 720 4/18/2017
1.0.0-beta4 1,056 8/31/2016
1.0.0-beta3 923 7/31/2016
1.0.0-beta2 933 7/5/2016
1.0.0-beta1 806 2/1/2016
0.9.44 2,426 8/5/2015
0.9.43 914 8/4/2015
0.9.42 1,015 8/4/2015
0.9.41 1,013 7/11/2015
0.9.40 1,054 7/11/2015
0.9.31 1,366 2/10/2015
0.9.30 1,068 2/9/2015
0.9.2 948 2/6/2015
0.9.1 1,320 1/24/2015
0.9.0 1,371 12/23/2014
0.8.47 1,968 4/17/2014
0.7.46 1,207 4/2/2014
0.5.44 1,133 3/26/2014
0.3.43 1,018 3/7/2014
0.2.42 1,034 3/6/2014
0.2.41 1,032 3/5/2014