The Castle MicroKernel Registration API is also used in Windsor, and both have a facility to allow a components to subscribe to events exposed by each other. Right now, the only way to use the fluent API to configure the facility is to go right down and build the configuration nodes (taken from http://blogger.forgottenskies.com/?p=266):
This works fine, but it’s a little verbose for my liking. I’ve managed to get it down to:
Much nicer! In effect all I’ve done is abstract away the building of the configuration nodes. Firstly I have a Subscriber class:
Then the actual business end of things is the Extension method which allows me to use this:
As you can see, I’m just pulling out the data from the SubscriberInfo array and building up the configuration nodes. These are then passed to a ConfigurationDescriptor which is where the real business happens. Writing a custom descriptor would probably make for a more elegant solution, so if anyone’s got any suggestions then I’m all ears. When I work out how to write a test for this behaviour I’ll try and sort out a Castle patch.