开发者

Using a Dependency Injection Container in an enterprise solution with multiple different configurations

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, o开发者_如何转开发ffice 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.


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.
    }
}


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜