2009-07-27 2 views
1

필자가 작성한 인터셉터를 얻으려고하는데, 어떤 이유로 구성 요소를 요청할 때 인터셉터를 인스턴스화하지 않는 것 같습니다.Fluent 인터페이스가있는 Castle 인터셉터

container.Register(
    Component.For<MyInterceptor>().LifeStyle.Transient, 
    AllTypes.Pick().FromAssembly(...).If(t => typeof(IView).IsAssignableFrom(t)). 
    Configure(c => c.LifeStyle.Is(LifestyleType.Transient).Named(...). 
        Interceptors(new InterceptorReference(typeof(MyInterceptor)). 
    WithService.FromInterface(typeof(IView))); 

을 나는 인터셉터의 생성자에서 중단 점을 넣었습니다 그것은하지 않는 것 :이 (이 꽤 컴파일하지 않는 경우 용서,하지만 당신은 아이디어를 얻을합니다) 뭔가를하고 있어요 그것을 전혀 인스턴스화하는 것.

이전에는 XML 구성을 사용하여 인터셉터를 등록했지만 유창한 인터페이스를 사용하고자합니다.

는 어떤 도움을 크게 감상 할 수있다!

답변

6

나는 당신이 오용이라고 생각합니다. WithService.FromInterface. 문서는 다음과 같이 말합니다.

하위 인터페이스를 찾으려면 도구를 사용하십시오. 예 : IService 및 IProductService가있는 경우 : ISomeInterface, IService, ISomeOtherInterface. FromInterface (typeof (IService))를 호출하면 IProductService가 사용됩니다. 유용 모두 서비스를 등록하고 싶지만 을 지정하고 싶지는 않습니다.

또한 InterceptorGroup Anywhere이 누락되었습니다. 나는 이것이 단지의 경우 추측,

이 작동
[TestFixture] 
public class PPTests { 
    public interface IFoo { 
     void Do(); 
    } 

    public class Foo : IFoo { 
     public void Do() {} 
    } 

    public class MyInterceptor : IInterceptor { 
     public void Intercept(IInvocation invocation) { 
      Console.WriteLine("intercepted"); 
     } 
    } 

    [Test] 
    public void Interceptor() { 
     var container = new WindsorContainer(); 

     container.Register(
      Component.For<MyInterceptor>().LifeStyle.Transient, 
      AllTypes.Pick() 
       .From(typeof (Foo)) 
       .If(t => typeof (IFoo).IsAssignableFrom(t)) 
       .Configure(c => c.LifeStyle.Is(LifestyleType.Transient) 
            .Interceptors(new InterceptorReference(typeof (MyInterceptor))).Anywhere) 
       .WithService.Select(new[] {typeof(IFoo)})); 

     container.Resolve<IFoo>().Do(); 
    } 
} 
+0

, 내가 그냥 InterceptorGroup에 어느 곳을 잃어버린 것 같다 여기에 나는 그것이 작동하도록 샘플에서 가능한 한 적게 변경 작업 샘플입니다 나에게 워드 프로세서를 읽지 않는다. WithService.Select()는 내가 원하는 IView 인터페이스를 선택하지 않는 것 같습니다. 여러 번 구현 되었기 때문에 (묻지 마세요) FromService는 트릭을 수행하는 것 같습니다. – jonnii