views:

223

answers:

1

I have the following bit of registration code:

Component.For<IPublishingService>().ImplementedBy<UseStoredProcedureToPrintService>(),
Component.For<IConfirmationDialog<AutomatedTransaction>>().ImplementedBy<ShipmentConfirmationDialog>().Named("ShipmentConfirmationDialog"),
Component.For<IConfirmationService<AutomatedTransaction>>().ImplementedBy<SingleTransactionConfirmation>().ServiceOverrides(
    ServiceOverride.ForKey("shipmentDialog").Eq("ShipmentConfirmationDialog") ),

A requirement came down the line that in some instances the application is supposed to behave somewhat differently. Great I thought, this is exactly what I was using Castle Windsor for to begin with.

So I wrote my new components and I register them first. For example, I implement IPublishingService differently and register the new implementation first so that it is resolved over the default one above. However, a problem occurrs in the few cases where I had no choice but to use an id to wire up my service overrides. For example how do I redirect the ServiceOverride for ShipmentConfirmationDialog to use my new SpecialCaseShipmentConfirmationDialog implementation without modifying the bit of code above?

There are all sorts of mechanisms in castle windsor that I don't really understand like forwarding and ActAs that I'm hoping will provide a simple answer.

+2  A: 

I'd keep it simple. If it's configurable, put it in the config (web.config / app.config) then just load the ID using ConfigurationManager.AppSettings["shipmentDialogToUse"];

Also remember that the fluent registration API is not the be-all and end-all of registration. XML still has its time and place where it's the right tool for the job.

Mauricio Scheffer
I think its the right tool for the job when you need to make changes to a deployed app. Otherwise, just put all registration into Registrar classes and add a simple dynamic discovery mechanism which finds Registrar all local dlls.In my case I have an app that can be deployed against 2 very different data bases so I need to deploy it with different model translation layers and a couple different UI screens. Since all the configuration is deployment-time I don't really see why xml config is necessary (though I allow it too).Point taken though. Still too bad there's no override mechanism.
George Mauer