Autofac has modules, Windsor has Installers and StructureMap Registries ... with Simple Injector how can I pack configuration logic into reusable classes?
I have tried:
public interface IModule { }
public class FooModule : IModule
{
public FooModule(SimpleInjector.Container container)
{
container.RegisterSingleton<IBar, Bar>();
container.RegisterSingleton<IFoo, Foo>();
}
}
And I use it in the Composition Root:
public static void Main(string[] args)
{
var container = new SimpleInjector.Container();
container.RegisterCollection<IModule>(new FooModule(container));
...
}
However, FooModule
depends on container and maybe in not a good practice...
see http://code.google.com/p/autofac/wiki/BestPractices:
If components have a dependency on the container, look at how they're using the container to retrieve services, and add those services to the component's (dependency injected) constructor arguments instead.