推荐阅读:
最近实现了一个 AOP 框架 – FluentAspects,API 基本稳定了,写篇文章分享一下这个 AOP 框架的设计。
整体设计
概览
IProxyTypeFactory
用来生成代理类型,默认提供了基于 Emit 动态代理的实现,基于接口设计,可以扩展为其他实现方式
接口定义如下:
public interface IProxyTypeFactory
{
Type CreateProxyType(Type serviceType);
Type CreateProxyType(Type serviceType, Type implementType);
}
IProxyFactory
用来生成代理实例,默认实现是基于 IProxyTypeFactory
生成代理类型之后创建实例
接口定义如下:
public interface IProxyFactory
{
object CreateProxy(Type serviceType, object[] arguments);
object CreateProxy(Type serviceType, Type implementType, params object[] arguments);
object CreateProxyWithTarget(Type serviceType, object implement, object[] arguments);
}
IInvocation
执行上下文,默认实现就是方法执行的上下文,包含了代理方法信息、被代理的方法信息、方法参数,返回值以及用来自定义扩展的一个 Properties
属性
public interface IInvocation
{
MethodInfo ProxyMethod