Core components for the OutWit static proxy generator. Contains the essential interfaces and attributes needed to define interception logic and use the generated proxies.
$ dotnet add package OutWit.Common.ProxyOutWit.Common.Proxy provides foundational classes and interfaces for creating proxy objects using static code generation. The library is designed for environments where dynamic generation (e.g., Castle DynamicProxy) is not feasible, such as AoT compilation or Blazor.
Interface for creating interceptors (IProxyInterceptor):
Allows developers to configure interception of method, property, and event calls.
ProxyTargetAttribute:
Used to mark interfaces that should be processed by the proxy generator.
IProxyInvocation Interface:
Provides details about the invocation, including method name, parameters, return values, and their types.
Add OutWit.Common.Proxy to your project via NuGet:
dotnet add package OutWit.Common.Proxy
Define an interface and mark it with the ProxyTargetAttribute:
using OutWit.Common.Proxy;
[ProxyTarget]
public interface IExampleService
{
string GetData(int id);
event EventHandler DataChanged;
}
Implement a class that implements IProxyInterceptor to handle calls:
public class ExampleInterceptor : IProxyInterceptor
{
public void Intercept(IProxyInvocation invocation)
{
Console.WriteLine($"Intercepted method: {invocation.MethodName}");
if (invocation.MethodName == "GetData")
{
invocation.ReturnValue = $"Data for ID {invocation.Parameters[0]}";
}
}
}
Integrate the OutWit.Common.Proxy.Generator library to generate the proxy for your interface (refer to README.md for OutWit.Common.Proxy.Generator).
ProxyTargetAttribute:
An attribute to mark interfaces that are processed by the proxy generator.
IProxyInterceptor:
Interface for creating a handler for method, property, and event calls.
IProxyInvocation:
Interface that describes a method/property/event invocation.
ProxyInvocation:
Implementation of IProxyInvocation.
Licensed under the Apache License, Version 2.0. See LICENSE.
If you use OutWit.Common.Proxy in a product, a mention is appreciated (but not required), for example: "Powered by OutWit.Common.Proxy (https://ratner.io/)".
"OutWit" and the OutWit logo are used to identify the official project by Dmitry Ratner.
You may:
You may not: