Hi.
I'm trying to get StructureMap to put a Castle.DynamicProxy around some of the objects it creates. I have used the EnrichWith-feature earlier, but I think RegisterInterception would suit me better in this case, since I use scanning.
The problem is that in the "Process(object target, IContext context)"-method, I can't find out which Interface SM is trying to get, only the concrete class. I could find all the interfaces this class implements, but in case it implements more than one interface, I have no idea how to find which Interface was actually requested. Is there any way to do this?
Here's some code:
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;
}
}