SidekickNet.Aspect.DynamicInheritance 1.0.1

dotnet add package SidekickNet.Aspect.DynamicInheritance --version 1.0.1                
NuGet\Install-Package SidekickNet.Aspect.DynamicInheritance -Version 1.0.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SidekickNet.Aspect.DynamicInheritance" Version="1.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SidekickNet.Aspect.DynamicInheritance --version 1.0.1                
#r "nuget: SidekickNet.Aspect.DynamicInheritance, 1.0.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install SidekickNet.Aspect.DynamicInheritance as a Cake Addin
#addin nuget:?package=SidekickNet.Aspect.DynamicInheritance&version=1.0.1

// Install SidekickNet.Aspect.DynamicInheritance as a Cake Tool
#tool nuget:?package=SidekickNet.Aspect.DynamicInheritance&version=1.0.1                

SidekickNet

SidekickNet provides common utilities for .NET (.NET Standard 2.0 and above).

Aspect-oriented Programming

One of the important utilities provided by SidekickNet is Aspect-oriented Programming. There are three projects for AOP:

  • Aspect provides the framework and interfaces of AOP. It uses proxy objects for add advices to objects.
    • It doesn't provide implementations of proxy objects and proxy creation, because there are many possible implementations. Two reference implemenations are provided below that can be directly used.
  • Aspect.DynamicInheritance implements proxy objects using dynamic inheritance.
    • This implemenation is optimized for performance by generating IL code directly.
  • Aspect.SimpleInjector implements automatic proxy creation using SimpleInjector.
    • Dependency Injection is a convenient way of proxy creation. But other implementation are also possible.

AOP Example

Assume we want to log method entrance easily. First, create an "advice" that specifies what to do upon method entrace.

[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
internal class LoggingAdviceAttribute : AdviceAttribute
{
    public override void Apply(IInvocationInfo invocation)
    {
        // Advice action - log the entrance of the method
        Console.WriteLine($"Entering {invocation.Method.Name}");

        // Continue with the original method
        this.Proceed(invocation);
    }
}

Then, apply the "advice" to the target method.

public class Foo : IFoo
{
    // Adding the advice attribute is enough to automatically run the logging code
    // Note the method must be "virtual" for dynamic inheritance to work
    [LoggingAdvice]
    public virtual void DoSomething()
    {
        // Business logic
    }
}

Finally, register how proxies will be created. In this case we use Simple Injector.

public void Initialize()
{
    // Create the DI container
    var container = new Container();

    // The proxy factory provided by an implementation, such as Dynamic Inheritance
    var proxyFactory = new ProxyFactory();

    // Tell the DI container to create a proxy object when an object is requested
    container.InterceptTarget(
        type => proxyFactory.GetProxyType(type).GetConstructors()[0]);

    // Register the advice in the container
    container.Register<LoggingAdviceAttribute>();

    // Register the regular types
    container.Register<IFoo, Foo>();

    // The "foo" object obtained from the DI container
    // is actually a proxy that will apply the advice and invoke the origianl method
    var foo = container.Get<IFoo>();

    // Print "Entering DoSomething" before actualy do something
    foo.DoSomething();
}

The Aspect.Test unit test project contains more examples, such as advice bundles.

Other Utilities

  • Utilities provides common helpers for strings, collections, exceptions, etc.
  • Utilities.AspNetCore provides ASP.NET Core helpers, such as YAML (instead of JSON) configuration files.
Product 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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.1 75 11/14/2024
1.0.0 68 11/14/2024
0.3.9 223 6/7/2023
0.3.8 155 6/6/2023
0.3.2 462 7/13/2022
0.3.1 432 6/13/2022
0.3.0 837 12/14/2021
0.2.2 403 7/2/2021
0.2.0 449 8/29/2020