This project demonstrates the use of Metalama aspects to generate RPC proxy classes for interfaces in C#. It avoids the use of DispatchProxy and instead leverages a custom Metalama aspect to automatically generate proxy implementations that delegate method calls to a transport layer.
- Metalama Aspect: Uses a custom
RpcProxyAspectto generate proxy classes for interfaces. - Transport Abstraction: All RPC calls are routed through an
IRpcTransportimplementation. - No DispatchProxy: The solution does not use .NET's
DispatchProxy. - Automatic Proxy Generation: Proxy classes are generated at compile time for any interface annotated with the aspect.
MetaLama-Test/IMyService.cs: Example service interface.MetaLama-Test/Program.cs: Example usage of the generated proxy.MetaLama-Test/RpcTransport.cs: Example transport implementation.Proxy/IRpcTransport.cs: Transport abstraction interface.Proxy/RpcProxyAspect.cs: Metalama aspect for proxy generation.
- Annotate your service interface with
[RpcProxyAspect(typeof(MyTransport))]. - The aspect generates a proxy class (e.g.,
MyServiceProxy) implementing the interface. - The proxy delegates all method calls to the provided transport.
- Use the generated proxy in your application by passing an
IRpcTransportinstance.
var transport = new RpcTransport();
var proxy = new Proxies.MyServiceProxy(transport);
var result = proxy.Add(1, 2);- .NET 9.0 or later
- Metalama
- Restore NuGet packages.
- Build the solution.
- Run the
MetaLama-Testproject.
GPL-3.0 License