views:

34

answers:

1

Hello everybody,

I do have the following class: public class MainView : IHandle<MessageOne>,
IHandle<MessageTwo>...

I would like to register all classes implementing at least one closed version of the IHandle<> Interface with the fluent registration of Castle Windsor but it does not work. BasedOn(typeof(IHandleThe<>)) is not selecting the right types. I use the following statement:

container.Register(AllTypes
                     .FromAssemblyNamed("MyAssembly")
                   //.If(t => t.Name.EndsWith("View")
                     .BasedOn(typeof(IHandleThe<>))
                     .Configure(registration => DoStuff())
                     .WithService.Base);

The above code does not get into the Configure call but when I comment the BasedOn line and uncomment the If line, then it works. The If is not too helpful, though. Does anybody have an idea what I am doing wrong.

Any ideas/help is appreciated

Best regards Gope

A: 

That's one of less intuitive things about the API. If you take a look at the documentation, you'll find that Pick BasedOn and Where do xor, so the code above would register two sets of types:

  1. Types that have name ending with "View" (with default connfiguration, that is as themseles)

  2. Types that are based on IHandleThe<> (all of them found in the assembly, the previous condition does not apply here) and configure them to the base service, and whatever the DoStuff method does.

To achieve what you want (based on the type AND if name ends with If) the BasedOn call must go first, all the other ones must go after it.

Krzysztof Koźmic
Hello Krzysztof and thanks for helping, the point is: just BasedOn() does not work. The If-Line is only for Stackoverflow to show people that the BasedOn version is not working but using the if without BasedOn does. Just to prove it is not a too stupid mistake like the assembly is not there. I only want types implementing IHandleThe<>. Nothing with a name like "View". But I do understand that you would expect the above code to work like it is (with the commented or deleted if-line). Any other idea what could be the cause?
Gope
ok, which version are you using? Are you sure there are any types implementing `IHandlerThe<>` in that assembly? I've written code like this on quite a few projects - it **has to** work
Krzysztof Koźmic
Yup, IHandleThe<> is implemented by one Class (MainView) and the configure part relies on that type which is working with the if line. So that can't be the problem but maybee the version? The Castle.Windsor.dll is of version 2.1.0.6655. I copied it over from a friends Rhino-ESB demo. Could there be problems with 64/32 bit stuff in the Castle assemblies? I just found that 2 of my 4 Projects have a build type of x86 while the others (without referenced external assemblies) are on anyCPU... strange... by the way, its all on .NET 4.0
Gope
I can't really say I know what the problem is. As it usually turns out in situations like this it's something stupidly obvious, yet I don't know what could that be. How are the types registered? Are they registered at all?
Krzysztof Koźmic
I think you're right. As this is just a demo for the service-bus stuff it's not too much of a problem. I will try this in a new blank solution and if it works nevermind. But first thanks for your support and also many thanks for putting your precious time into the Castle Project. There are lots of people really appreciating that! Cheers, Gope
Gope

related questions