In my StructureMap bootstrapping code I\'m using a custom convention to scan assemblies and add interface/implementation pairs to the object graph as named instances. Essen
The Add
method will add instances (if you need to add named instances or add multiple instances for to use with collections/enumerations). If no explicit default is registered (using the Use
method), the last instance added will become the default instance. The Use
method is intended for setting the default instance. If you invoke Use
multiple times, the last instance registered will become default.
In order to set a default instance and then register further named instances you should be able to do it like this:
registry.For(typeof(Logger)).Use(typeof(Log4Net)).Named("Log4Net");
registry.For(typeof(Logger)).Add(typeof(Mock)).Named("Mock");
This will make the Log4Net
instance the default and also accessible as a named instance. The Mock
instance will be available as a named instance.