c# - Windsor not resolving intercepted components -
Can anyone explain why this does not work? If you remove the interceptor from the registration of IFoo and solve it once, then you get a fu (not a Mufu faucet). But with the interceptor, Fu does not solve anymore.
Why? How can I tell if it will not solve it through logging or tracing?
Version:
- Castle .Cor: 3.2
- Castle. Windows: 3.2
- Using .NET 4.5
-
C # 5
Using Castle Dynamic Proxy; Using Castle.MicroKernel.Registration; Castle use Windsor; Using the system; Namespace Sandbox {Public Interface IFooInterceptor: IInterceptor {} Public Interface IFoo {void Print (); } Public Interface ib {iFu Mifu {receives; Set; }} Public Category Foo: IFoo {Public Zero Print () {Console.WriteLine ("Print"); }} Public Class FooInterceptor: IFooInterceptor, IInterceptor {IInvocation invocation} {Console.WriteLine ("Awesome"); Invocation.Proceed (); }} Public Class Bar: IBR {public virtual IFoo MyFoo {get; Set; }} Class program {static void key (string [] args) {IWindsorContainer container = new WindsorContainer () .Register (Component.For & lt; Ibar & gt; () ImplementedBy. & Lt; Bar & gt; () LifestyleTransient (), Component.For & gt; IFoo & gt;. () ImplementedBy & lt; foo & gt; () LifestyleTransient () Interceptors. & Lt;. IFooInterceptor & gt; (), Component.For & lt; IFooInterceptor & Gt; () ImplementedBy. & Lt; FooInterceptor & gt ;. () LifestyleTransient ()); Var Bar = Container Resolver & lt; IBar & gt; (); Var foo = Container. Resolver & lt; IFoo & gt; (); // This is not a tap bar. Myfu Print (); // Exception: bar.MyFoo is the null console. Light Line ("Done"); Console.ReadLine (); I have just found (mostly by accident) that the interface works by changing the interceptor converter from one interface to the class, however, I am entering interceptor and its interface, so the original question is slightly modified:? Why the interface specification fails (quietly, not less)
Castle handles properties as alternate dependencies But it should inject them by default but it seems that Interceptors do not solve these optional dependencies correctly.
What you can do is you need to use bar manufacturer injection Change your own To make dependency:.
public class bar: IBR {public bar (IFU FU) {MAYFU = EFU; } Public Virtual IFoo MyFoo {get; Private set; }}
or
property markedly marked as required.
Component.For & LT; Ibar & gt; () ImplementedBy & lt; Bars & gt; () LifestyleTransient () .properties (Propa ???? one ???? ertyFilter.RequireAll)
Note:. In the output you should use
propertiesRequired properties instead of / code> method because it is now obsolete.
I also found this gitb problem which was also relevant:
Comments
Post a Comment