1

With StructureMap 2.6.4.1 (no, I haven't upgraded yet; soon though), I'm trying to do something like this:

Scan(scan => scan.AddAllTypesOf<IMap>()
      .NameBy(t => 
          {
              if (t.Namespace.IsNullOrWhiteSpace()) return null;
              if (t.Namespace.Contains("Foo")) return "Foo";
              if (t.Namespace.Contains("Bar")) return "Bar";
              return null;
          }));

And then later on:

container.GetAllInstances<IMap>("Bar"); // doesn't compile

My first question is this: is StructureMap intended to have only one concrete registration per name?

The only way I can think of getting around this is do something like this:

For<IEnumerable<IMap>>().Add(c =>
            {
                var maps = c.GetAllInstances<IMap>();
                var filteredMaps = maps
                    .Where(m => m.GetType().Namespace.Contains("Bar"))
                    .ToList();
                return filteredMaps;
            })
            .Named("Bar");

Is there a better way?

pdalbe01
  • 828
  • 7
  • 17

0 Answers0