views:

43

answers:

2

Can anyone point me towards some good documentation / code examples on how best to manage the configuration of a DI container in a scenario where you need different configuations sets?

We have a layered, distributed application that has multiple entry points (ie; a website, winforms app, office plugin etc). Depending on how you are using the solution (through a UI vs. an automated workflow for example), it needs to be configured slightly differently.

We are using Windsor, and it's fluent configuration capabilities.

A: 

You should have one container per application, so at that level you must configure each container for each application separately.

However, having a common base configuration for a family of applications is a normal requirement, and most DI Containers support that by providing a way in which you can package configurations.

In Castle Windsor, you do that by defining one or more classes that implement the IWindsorInstaller interface.

Example:

public class MyWindsorInstaller : IWindsorInstaller
{
    public void Install(IWindsorContainer container, IConfigurationStore store)
    {
        container.AddComponent<IFoo, Foo>();
        // etc.
    }
}
Mark Seemann
Looks like the most promising solution for us so far is combining IWindorInstaller usage with MEF -> http://kozmic.pl/archive/2009/04/05/meffing-with-castle-windsor.aspx
KevinT
A: 

We are supporting the "multiple configurations" situation by using XML configuration files. If you are ready to let go of fluent configuration, the XML configuration file set is pretty straight-forward to manage and deploy.

Jennifer Zouak