Skip to content

zhurongbo111/Castle.DynamicProxy.DependencyInjection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CastleDynamicProxy.DependencyInjection

This project is an extension to Castle DynamicProxy, it benefits you from DependencyInjection.

Packages

NuGet feed: https://www.nuget.org/packages/CastleDynamicProxy.DependencyInjection/

Package NuGet Stable Downloads
CastleDynamicProxy.DependencyInjection CastleDynamicProxy.DependencyInjection CastleDynamicProxy.DependencyInjection

What is Castle DynamicProxy?

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

What is CastleDynamicProxy.DependencyInjection?

It's an extension to Castle DynamicProxy, it benefits you from DependencyInjection.

How to use CastleDynamicProxy.DependencyInjection

Before use this library, it's probably safe to assume you are familiar with Castle DynamicProxy and Microsoft DependencyInjection.

Case 1: You want to add dynamic proxy for an interface

    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>();
    });

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages