Skip to content

Repository files navigation

Guard.DynamicProxy

A Lightweight Class Library for Generating Dynamic Proxy Objects Based on Emit.

1、Search for DynamicProxy. Core for installation through the nuget package.

2、Example

publicclassCalculate:ICalculate{publicvirtualintAdd(inta,intb){returna+b;}}publicinterfaceICalculate{intAdd(inta,intb);}publicclassLogInterceptor:IInterceptor{publicvoidIntercept(IInvocationinvocation){Debug.WriteLine("LogInterceptor pre....");invocation.Proceed();Debug.WriteLine("LogInterceptor post....");}}varbuilder=newDefaultProxyBuilder(newModuleScope());varproxyGenerator=newDefaultProxyGenerator(builder);//Using a public parameterless constructorvarcalculator=proxyGenerator.CreateInterfaceProxy<ICalculate,Calculate>(newLogInterceptor());//or Specify Constructorcalculator=proxyGenerator.CreateInterfaceProxy<ICalculate,Calculate>(newobject[]{"test"},newLogInterceptor());//or with target calculator=proxyGenerator.CreateInterfaceProxyWithTarget<ICalculate,Calculate>(newCalculate(),newLogInterceptor());calculator.Add(1,3);//Ignore a method's proxy//Add the Ignore attribute on the method[Ignore]publicintMultiply(inta,intb){returna*b;}

TODO

  • Dependency Injection
  • Code optimization

PS: This project draws on some of the code design from castle. dynamic. We hope everyone can point out more issues that need improvement, learn together, and improve together.

About

A Lightweight Class Library for Generating Dynamic Proxy Objects Based on Emit.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages