MassiveDynamicProxyGenerator 1.3.0-preview1

This is a prerelease version of MassiveDynamicProxyGenerator.
There is a newer version of this package available.
See the version list below for details.
Install-Package MassiveDynamicProxyGenerator -Version 1.3.0-preview1
dotnet add package MassiveDynamicProxyGenerator --version 1.3.0-preview1
<PackageReference Include="MassiveDynamicProxyGenerator" Version="1.3.0-preview1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MassiveDynamicProxyGenerator --version 1.3.0-preview1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: MassiveDynamicProxyGenerator, 1.3.0-preview1"
#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 MassiveDynamicProxyGenerator as a Cake Addin
#addin nuget:?package=MassiveDynamicProxyGenerator&version=1.3.0-preview1&prerelease

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


.Net library for generate proxy class instances

Massive Dynamic Proxy Generator is a library for generating lightweight .NET proxies on the fly at runtime. Proxy objects allow calls to members of an object to be intercepted without modifying the code of the class. Both classes and interfaces can be proxied, however only virtual members can be intercepted.


  • Proxy instance generator, for intercept.
  • Decorator generator.
  • Proxy instance generator, for control instancing real implementation (e.g. lazy loading).

The following platforms are supported:

  • .Net 4.0, 4.5, 4.6, 4.6.1, NetStandard 1.6, NetStandard 2.0 and UWP applications (NetStandard 1.4)

Generate decorator

 ProxyGenerator generator = new ProxyGenerator();
 Calculator realInstance = new Calculator();
 ICallableInterceptor interceptor = new CallableInterceptorAdapter((invocation) =>
     Console.WriteLine(" Log: Call method {0}", invocation.MethodName);
         Console.WriteLine(" Log: return: {0}", invocation.ReturnValue ?? "null");
     catch(Exception ex)
         Console.WriteLine(" Log: Exception message: {0}", ex.Message);

 ICalculator decorator = generator.GenerateDecorator<ICalculator>(interceptor, realInstance);

 Console.WriteLine("Before call Add with 2013 and 6");
 int result = decorator.Add(2013, 6);
 Console.WriteLine("Result is {0}", result);

Generate proxy

IInterceptor jsonRpcInterceptor = new InterceptorAdapter((invocation, isDynamic) =>
    Guid requestId = Guid.NewGuid();
    var rcpBody = new
        jsonrpc = "2.0",
        method = invocation.MethodName,
        @params = invocation.Arguments,
        id = requestId.ToString()

    string serialized = Newtonsoft.Json.JsonConvert.SerializeObject(rcpBody);

    //simulate sending and recrive

    Console.WriteLine(" Sending Rpc: {0}", serialized);
    string recText = $"{{\"jsonrpc\": \"2.0\", \"result\": 19, \"id\": \"{requestId.ToString()}\"}}";
    Console.WriteLine(" Rec Rpc: {0}", recText);

    Newtonsoft.Json.Linq.JObject response = Newtonsoft.Json.JsonConvert.DeserializeObject< Newtonsoft.Json.Linq.JObject>(recText);
    invocation.ReturnValue = response["result"].ToObject(invocation.ReturnType);

ProxyGenerator generator = new ProxyGenerator();

ICalculator calcilator = generator.GenerateProxy<ICalculator>(jsonRpcInterceptor);

int resultModulo = calcilator.Modulo(15, 4);

Console.WriteLine("Modulo 15 and 4 is {0}", resultModulo);

int resultProduct = calcilator.Product(8, 486);

Console.WriteLine("Product 8 and 486 is {0}", resultProduct);

Generate instance proxy

IInstanceProvicer instanceProvider = new LazyInstanceProvider<ICalculator>(
    () =>
        Console.WriteLine(" Log: Create Calculator.");
        return new Calculator();
    }, false);

ProxyGenerator generator = new ProxyGenerator();
ICalculator  calculator = generator.GenerateInstanceProxy<ICalculator>(instanceProvider);

Console.WriteLine("Before call Add with 2013 and 6");
int result = calculator.Add(2013, 6);
Console.WriteLine("Result is {0}", result);

Console.WriteLine("Before call Product with 2013 and 6");
int result2 = calculator.Product(2013, 6);
Console.WriteLine("Result is {0}", result2);

NuGet packages (3)

Showing the top 3 NuGet packages that depend on MassiveDynamicProxyGenerator:

Package Downloads

MassiveDynamicProxyGenerator.SimpleInjector is library of extensions method for IoC container - Simple Injector. Adding methods for register mock implementations, proxys, instance proxies for resolving circular depndencies or lazy initialization and interpetion for decoration instances.


MassiveDynamicProxyGenerator Microsoft.Extensions.DependencyInjection is intergration MassiveDynamicProxyGenerator to standard IoC container in ASP.NET Core.


A type-safe REST library

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.5.0 2,160 11/24/2020
1.4.0 3,069 8/27/2019
1.3.0 2,819 7/10/2018
1.3.0-preview1 821 5/8/2018
1.2.2 901 4/14/2018
1.2.1 976 8/21/2017
1.2.0 991 6/28/2017
1.2.0-beta1 917 6/13/2017
1.1.0 942 3/22/2017
1.0.0 972 12/1/2016

Change interface IInvocation.
Add universal async ibterceptor CallableInterceptorAsyncAdapter as abstract class for handle error in async task.
Add support for .Net Stdard 2.0.

Fix typo error ProxygGenerator -> ProxyGenerator.