SWZR.Dynamxy 0.1.0

Install-Package SWZR.Dynamxy -Version 0.1.0
dotnet add package SWZR.Dynamxy --version 0.1.0
<PackageReference Include="SWZR.Dynamxy" Version="0.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SWZR.Dynamxy --version 0.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: SWZR.Dynamxy, 0.1.0"
#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 SWZR.Dynamxy as a Cake Addin
#addin nuget:?package=SWZR.Dynamxy&version=0.1.0

// Install SWZR.Dynamxy as a Cake Tool
#tool nuget:?package=SWZR.Dynamxy&version=0.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Dynamxy

Library for .NET enabling the use of dynamic proxy objects.

Getting Started

Either fork, clone or download this repository. Or install the library via NuGet:

Install-Package SWZR.Dynamxy

How does it work

During instantiation of a proxy object, code is dynamically emitted using primarly IL to create a concrete implementation based on a given interface. This type functions as intermediary and forwards any method call to the predefined interceptor.

Usage

In order to use dynamic proxy objects first define an interface:

public interface ITestInterface
{
	object Echo(object obj);
}

Afterwards define an interceptor which handles all method calls:

using System.Reflection;
using SWZR.Dynamxy;

public class EchoInterceptor : IInterceptor
{
    public object InterceptMethod(object instance, MethodInfo info, object[] parameter)
    {
        return parameter.Length > 0 ? parameter[0] : null;
    }
}

The last step is to construct an instance of the interceptor and eventually the dynamic proxy itself:

var factory = new ProxyFactory<EchoInterceptor>();
var proxy = factory.Create<ITestInterface>();

// Will yield 'Hello World'.
var value = proxy.Echo("Hello World");

Use Cases

  • Authorization
  • Logging
  • REST
  • RPC
  • ...

Roadmap

  • Improve and extend unit tests
  • Allow intercepting methods of concrete types
  • Add an example

License

This project is licensed under the MIT License - see the LICENSE.md file for details

This package has no dependencies.

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
0.1.0 527 3/15/2018