Microsoft Unity DI offers a feature where you can register multiple objects for the same interface and give them a name. Then in your constructor you can use an attribute with the argument to specify by name which object you want to inject.
I am wondering how to achieve this same functionality using StructureMap.
Example:
container
.RegisterType<IMappingEngine, MappingEngine>("MappingEngineOne", new HierarchicalLifetimeManager(), new InjectionConstructor(typeof(MappingEngineOneConfiguration)))
.RegisterType<IMappingEngine, MappingEngine>("MappingEngineTwo", new HierarchicalLifetimeManager(), new InjectionConstructor(typeof(MappingEngineTwoConfiguration)))
....
public class MyServiceAgent {
private readonly IMappingEngine _mapper;
public MyServiceAgent([Dependency("MappingEngineOne")] IMappingEngine mapper) {
_mapper = mapper;
}
}
public class MyOtherServiceAgent {
private readonly IMappingEngine _mapper;
public MyOtherServiceAgent ([Dependency("MappingEngineTwo")] IMappingEngine mapper) {
_mapper = mapper;
}
}