This project is an extension to Castle DynamicProxy, it benefits you from DependencyInjection.
NuGet feed: https://www.nuget.org/packages/CastleDynamicProxy.DependencyInjection/
Package | NuGet Stable | Downloads |
---|---|---|
CastleDynamicProxy.DependencyInjection |
DynamicProxy generates proxies for your objects that you can use to transparently add or alter behavior to them, provide pre/post processing and many other things. For detailed info, please refer to Dynamic Proxy
It's an extension to Castle DynamicProxy, it benefits you from DependencyInjection.
Before use this library, it's probably safe to assume you are familiar with Castle DynamicProxy and Microsoft DependencyInjection.
public interface IMyInterface
{
void Say();
}
public class MyImpl : IMyInterface
{
public void Say()
{
System.Console.WriteLine("Say is called");
}
}
public class TestInterceptor : IInterceptor
{
public void Intercept(IInvocation invocation)
{
System.Console.WriteLine("Called before method executing.");
invocation.Proceed();
System.Console.WriteLine("Called after method executed.");
}
}
When you add your interface to container, you can use following:
services.AddTransient<TestInterceptor>();
services.AddTransientProxyService<IMyInterface, MyImpl>(proxybuilder =>
{
proxybuilder.WithInterceptor<TestInterceptor>();
});