Reacting to my previous post, Krzysztof Koźmic was so kind to point out to me that I really should be using an IWindsorInstaller instead of writing the registration code in a static helper method (it did make me cringe a bit).
As it turns out, IWindsorInstaller is not a particularly well-described feature of Castle Windsor, so here's a quick introduction. Fortunately, it is very easy to understand.
The idea is simply to package configuration code in reusable modules (just like the Guice modules from Uncle Bob's post).
Refactoring the bootstrap code from my previous post, I can now move all the container configuration code into a reusable module:
public class BillingContainerInstaller : IWindsorInstaller
{
#region IWindsorInstaller Members
public void Install(IWindsorContainer container,
IConfigurationStore store)
container.AddComponent<TransactionLog,
DatabaseTransactionLog>();
container.AddComponent<CreditCardProcessor,
MyCreditCardProcessor>();
container.AddComponent<BillingService>();
}
#endregion
While I was at it, I also changed from the fluent registration API to the generic registration methods as I didn't really need the full API, but I could have left it as it was.
BillingContainerInstaller implements IWindsorInstaller, and I can now configure my container instance like this:
var container = new WindsorContainer();
container.Install(new BillingContainerInstaller());
The Install method takes a parameter array of IWindsorInstaller instances, so you can pass as many as you'd like.
Remember Me
a@href@title, b, em, i, strike, strong
Page rendered at Saturday, February 04, 2012 8:32:48 PM (Romance Standard Time, UTC+01:00)
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.