I really like the new component registration API in Castle Windsor, if you compile the trunk yourself with Visual Studio 2008 you also get some .NET 3.5 only methods that uses lambda functions. These new functions make the API really powerfull.

// Register services
Container.Register(AllTypes.Pick()
.FromAssembly(Assembly.GetExecutingAssembly())
.If(type => type.Namespace == typeof(ISearchService).Namespace)
.WithService.FirstInterface());

This registers all classes that exists in the same namespace as the ISearchService interface. When windsor registers the classes it will take the first interface as the main interface (the one you can use to get the component). The nice this is that this can be used together with the xml based configuration since only components that are not already registered will be added. This gives you a change to later change a component via the xml configuration.

Ayende has been posting a lot about automatic component registration using Binsor windsor configuration scripts. The programming experience when all components are registered and hooked up automatically is really nice. It lets you focus on the important stuff.

2 comments:

Jokei Dest said...

Wow! Exactly what I was looking for! You saved me a lot of googling!

But I think you should change the name of the blog to "SlickTorkl" or something, would sound better considering what you're writing about.

Torkel said...

I was thinker about UberTorkel, but I don't like be so modest :)