Hi, Having a problem with StructureMap IOC. I wish to retrieve different concrete implementations of objects that implement the same interface based on labels or names.
internal static class InstanceHelper
{
internal enum Taxonomy
{
Foo,
Bar
}
static InstanceHelper()
{
// Initialize the container
ObjectFactory.Initialize(x =>
{
x.For<IMyInterface>().Use<ObjectA>().Named(Taxonomy.Foo.ToString());
x.For<IMyInterface>().Use<ObjectB>().Named(Taxonomy.Bar.ToString());
});
}
internal static IMyInterface GetInstanceByTaxonomy(Taxonomy taxonomy)
{
// this raises an exception
ObjectFactory.GetNamedInstance<IMyInterface>(taxonomy.ToString());
}
}
Documentation is not to good in this regard, seems like all the examples out there are deprecated... using version 2.6.1.0
thanks.