2017-04-11 11 views
1

Unity에서 StructureMap으로 이전 중입니다. Unity의 InterceptionBehavior를 사용했습니다.StructureMap DynamicProxyInterceptor를 사용할 때 컨테이너에서 IInterceptionBehavior의 인스턴스를 어떻게 해결합니까?

구조체 맵 .InterceptWithDynamicProxyInterceptor을 사용하도록 전환 할 수 있다고 생각했지만 인터셉터는 종속성이 있으며 StructureMap을 사용하여 인터셉터를 작성하는 방법을 알아낼 수 없습니다.

var container = new Container(x => 
     { 
      x.For<IMathService>().Use<MathService>() 
       .InterceptWith(new DynamicProxyInterceptor<IMathService>(new IInterceptionBehavior[] 
       { 
        // I WANT TO COMPOSE THESE INTERCEPTORS 
        new NegatingInterceptor(), 
        new CachingInterceptor() 
       })); 
     }); 

는 순간 나는 그 해결책이 될 수도 생각할 수있는 유일한 방법은 정적 IOC의 클래스에서 내 IContainer를 노출하고 내 인터셉터에서 수동으로 종속성을 해결하는 것입니다.

결국 나는 동적 프록시를 데코레이터로 대체하려고 할 것입니다.하지만 저는 아직 그 단계에 있지 않습니다. 나는 단지 그것을 깨우고 가능한 한 빨리 다시 실행하고 싶기 때문에 추가 변경을하기 전에 다른 모든 변경 사항이 성공적이라는 것을 증명할 수 있습니다.

답변

1

좋아, 바보, 당신은 단지 DynamicProxyInterceptor 생성자

var container = new Container(x => 
    { 
     x.For<IMathService>().Use<MathService>() 
      .InterceptWith(new DynamicProxyInterceptor<IMathService>(
      new Type[] 
      { 
       // I WANT TO COMPOSE THESE INTERCEPTORS 
       typeof(NegatingInterceptor), 
       typeof(CachingInterceptor) 
      })); 
    }); 
대신 인스턴스 유형의 배열을 전달