IWindsorInstaller by Mark Seemann
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.
Comments
I'll have to investigate whether that still holds true. If so, I would be inclined to consider it a bug on Windsor's part, but it may be by design, influenced by considerations I simply have yet to realize.
was wondering where i could find a sample application that uses castle windsor and asp.net webforms?
Thank you for writing. Unfortunately, I'm not aware of such a sample application. Have you tried asking on the Castle Windsor forum?
This sounds very similar to the startable facility though, with the important difference that in this case you have some more arguments.
I am new to castle windsor. Could you please tell me the difference between container.AddComponent(...) & container.Register(component.For<...>..).
When we need to use AddComponent() / Register()?
Thanks in advance !
Thank you for your answer. I have an another clarification. What are the advantages offer the castle windsor framework rather than using the normal coding.
In addition to that, Castle Windsor (and Unity and Spring.NET) also supports interception.
I need another help about castle windsor.
Could you please tell about how to check whether the particular assembly registered or not in the castle container.
Actually i am using the below code for register the assembly. i need to avoid the registering process, if it was already registered.
container.Register(AllTypes.FromAssemblyNamed(pAssemblyName).Pick().WithService.DefaultInterface());
Thanks in advance.