3

In StructureMap you could declare a Forward<,> statement, that would allow for registering a single concrete instance to be resolved by multiple interfaces from the StructureMap documentation:

var container = new Container(_ =>
{
    // Let's make StatefulCache a SingletonThing in the container
    _.ForConcreteType<StatefulCache>().Configure.Singleton();

    _.Forward<StatefulCache, IReader>();
    _.Forward<StatefulCache, IWriter>();
});

container.GetInstance<IReader>().ShouldBeOfType<StatefulCache>();
container.GetInstance<IWriter>().ShouldBeOfType<StatefulCache>();

I am looking at potentially migrating to Lamar, the replacement for StructureMap but I am not seeing anything matching this in the registration options.

Is this possible in Lamar?

ahsteele
  • 26,243
  • 28
  • 134
  • 248
soren.enemaerke
  • 4,770
  • 5
  • 53
  • 80

1 Answers1

5

According to StructureMap documentation the syntax has consistently been confusing to users and the suggested replacement is:

_.For<IReader>().Use(c => c.GetInstance<StatefulCache>());

So I would suggest using this lambda approach.

karolgro
  • 181
  • 1
  • 8