【发布时间】:2010-05-07 14:20:07
【问题描述】:
我试图让 StructureMap 在它创建的一些对象周围放置一个 Castle.DynamicProxy。我之前使用过 EnrichWith 功能,但我认为 RegisterInterception 在这种情况下更适合我,因为我使用了扫描。
问题在于,在“Process(object target, IContext context)”方法中,我无法找出 SM 试图获取的接口,只有具体的类。我可以找到这个类实现的所有接口,但如果它实现了多个接口,我不知道如何找到实际请求的接口。有没有办法做到这一点?
这里有一些代码:
public class SMInterceptor : TypeInterceptor
{
private readonly IInterceptor _interceptor;
private readonly ProxyGenerator _proxyGenerator;
public SMInterceptor(IInterceptor interceptor, ProxyGenerator proxyGenerator)
{
_interceptor = interceptor;
_proxyGenerator = proxyGenerator;
}
public static List<Type> TypesToIntercept = new List<Type>();
public object Process(object target, IContext context)
{
var interfaceToTarget = // This is where I want the target interface!
var decorator = _proxyGenerator.CreateInterfaceProxyWithTarget(interfaceToTarget, target, _interceptor);
return decorator;
}
public bool MatchesType(Type type)
{
return true;
}
}
【问题讨论】:
标签: .net structuremap aop ioc-container