IHandlerSelector broken in 3.0?

59 views
Skip to first unread message

mynkow

unread,
Jan 12, 2012, 8:34:32 AM1/12/12
to castle-pro...@googlegroups.com
Hi

I have some HandlerSelector/s which do not work after I upgraded to 3.0

First I add the selector: 
kernel.AddHandlerSelector(new DefaultRegistrationPolicyHandlerSelector());

and then I hit the class in debug mode. The IHandler[] handlers parameter is empty :( Any idea why?

class 
DefaultRegistrationPolicyHandlerSelectorIHandlerSelector
        {
            // Other code...
            public IHandler SelectHandler(string key, Type service, IHandler[] handlers)
            {
                return handlers.Where(x => x.ComponentModel.Implementation == typeof(NoRegistrationPolicy)).First();
            }
        }

mynkow

unread,
Jan 12, 2012, 10:24:43 AM1/12/12
to castle-pro...@googlegroups.com
Ok, I moved this code:

Component.For<IRegistrationPolicy>().ImplementedBy<NoRegistrationPolicy>().LifeStyle.Is(lifeStyle),
                Component.For<IRegistrationPolicy>().ImplementedBy<DefaultRegistrationPolicy>().LifeStyle.Is(lifeStyle),

to be executed before:
kernel.AddHandlerSelector(new DefaultRegistrationPolicyHandlerSelector());

and now is working. Very strange.

Krzysztof Koźmic

unread,
Jan 12, 2012, 3:48:39 PM1/12/12
to castle-pro...@googlegroups.com
Can you reproduce the invalid behaviour in test?
--
You received this message because you are subscribed to the Google Groups "Castle Project Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/castle-project-users/-/nKERlSVM4_IJ.
To post to this group, send email to castle-pro...@googlegroups.com.
To unsubscribe from this group, send email to castle-project-u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/castle-project-users?hl=en.

mynkow

unread,
Jan 12, 2012, 3:51:33 PM1/12/12
to castle-pro...@googlegroups.com
I will try tomorrow. I have no idea how to fix the other breaking change so I will have time for a test to reproduce it.

mynkow

unread,
Jan 13, 2012, 2:56:35 PM1/13/12
to castle-pro...@googlegroups.com
As I promised here is the failing test.


When you run the test an exception is thrown. I am not sure if all this stuff like facilities should be there to reproduce it but the important part is that is is failing. I also tried to swap the code as I did in the application but it is still failing.

PS: May be I am doing something wrong?

Krzysztof Koźmic

unread,
Jan 13, 2012, 5:11:21 PM1/13/12
to castle-pro...@googlegroups.com
Cheers,

That's a result of a breaking change (which I admit somehow didn't get documented in breakingchages.txt, or at least not explicitly)

Basically this is part of the same change as with ResolveAll method on the container - Windsor will now respect the services a component exposes, whereas previously it was just looking at the implementation type.

So you get an empty array, because there is no component exposing SecondComponent (or any assignable type) as a service. The only service in the container, exposed by two components, is ITestComponent.


How to make it work again, depends on what the real scenario does, and what your intention for this is.

HTH,
Krzysztof
--
You received this message because you are subscribed to the Google Groups "Castle Project Users" group.

mynkow

unread,
Jan 13, 2012, 5:38:33 PM1/13/12
to castle-pro...@googlegroups.com
Thanks for the explanation. Actually, I have a mistake in the gist code. In my application I am resolving ITestComponent.

Best Regards,
mynkow

Krzysztof Koźmic

unread,
Jan 13, 2012, 5:41:42 PM1/13/12
to castle-pro...@googlegroups.com
In that case the test will be green as the conditions in lines 20 and 35
will evaluate to false

> --
> You received this message because you are subscribed to the Google
> Groups "Castle Project Users" group.
> To view this discussion on the web visit

> https://groups.google.com/d/msg/castle-project-users/-/CxGpdDjLeqcJ.

Reply all
Reply to author
Forward
0 new messages