2010-05-07 6 views
1

나는 그것이 생성 한 개체 주위에 Castle.DynamicProxy를 넣기 위해 StructureMap을 얻으려고합니다. 이전에 EnrichWith 기능을 사용했지만,이 경우 RegisterInterception이 나를 잘 맞을 것이라고 생각합니다. 왜냐하면 검색을 사용하기 때문입니다.Interception 및 Castle.DynamicProxy가있는 StructureMap

문제는 "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; 
     } 
    } 

답변

0

늦은 비트,하지만 아래의 코드가 작동한다 (요청 된 유형의 인스턴스가 주어진)

var interfaceToTarget = context.BuildStack.Current.RequestedType; 
+0

이 매우 잘 작동하지 않습니다

는 여기에 몇 가지 코드입니다. http://pastie.org/1088333 이 반환 : 인터페이스 : ConsoleApplication1.IOne에게 대상 : ConsoleApplication1.Two 그리고 내가 정말 원하는 것은 이 작동하지 않습니다되었다 여기 간단한 콘솔 응용 프로그램 예제를 만들었습니다 맞아. 여기 간단한 콘솔 앱 예제를 만들었습니다. http://pastie.org/1088333 반환 값 : interface : ConsoleApplication1.ITwo – gautema