아무도 왜 이것이 작동하지 않는지 설명 할 수 있습니까? IFoo의 등록에서 인터셉터를 제거하고 막대를 해결하면 Foo가 생깁니다 (MyFoo는 null이 아닙니다). 그러나 인터셉터를 사용하면 Foo는 더 이상 해결하지 못합니다.윈저는 요격 된 구성 요소를 해결하지 않습니다
왜? 로깅 또는 추적을 통해 해결되지 않는 이유는 무엇입니까?
버전 :
- Castle.Core : 3.2
- Castle.Windsor : 3.2
- .NET 4.5
C# 5
using Castle.DynamicProxy; using Castle.MicroKernel.Registration; using Castle.Windsor; using System; namespace Sandbox { public interface IFooInterceptor : IInterceptor { } public interface IFoo { void Print(); } public interface IBar { IFoo MyFoo { get; set; } } public class Foo : IFoo { public void Print() { Console.WriteLine("Print"); } } public class FooInterceptor : IFooInterceptor, IInterceptor { public void Intercept(IInvocation invocation) { Console.WriteLine("Awesome"); invocation.Proceed(); } } public class Bar : IBar { public virtual IFoo MyFoo { get; set; } } class Program { static void Main(string[] args) { IWindsorContainer container = new WindsorContainer() .Register( Component.For<IBar>().ImplementedBy<Bar>().LifestyleTransient(), Component.For<IFoo>().ImplementedBy<Foo>().LifestyleTransient().Interceptors<IFooInterceptor>(), Component.For<IFooInterceptor>().ImplementedBy<FooInterceptor>().LifestyleTransient() ); var bar = container.Resolve<IBar>(); var foo = container.Resolve<IFoo>(); // this isn't null bar.MyFoo.Print(); // exception: bar.MyFoo is null Console.WriteLine("Done"); Console.ReadLine(); } } }
편집 : 인터페이스에서 구체적인 클래스로 인터셉터 구성을 변경하면 (대부분 우연히) 작동합니다. 그러나 인터셉터와 인터페이스를 등록하므로 원래 질문이 약간 수정됩니다. 인터페이스 사양이 실패하는 이유는 무엇입니까 (자동으로, 그다지 적지 않습니다)?
:
는 또한 또한 관련 듯이 github의 문제를 발견했습니다. – Amy이것은 버그 인 것 같습니다. 소유권은 선택적 종속성이지만 기본적으로 채워 져야하지만 어떻게 든 가로 채기와 충돌합니다. 'Component.For() .ImplementedBy () .LifestyleTransient() .Property (PropertyFilter.RequireAll)'로 의존성을 필수로 만들면 그것도 작동합니다. 나는이 문제를 github : https://github.com/castleproject/Windsor/issues/24에서 발견했다. –
nemesv
@nemesv 나는 질문을 대답하지 않은 채로 남겨 둘 수 있도록 대답으로 게시 할 수 있다고 생각합니다. Bar.MyFoo를 생성자 인수로 제공하면이 문제도 해결됩니다. – Marwijn