Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lamar alternative to StructureMap Forward()

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?

like image 495
soren.enemaerke Avatar asked Dec 30 '25 09:12

soren.enemaerke


1 Answers

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.

like image 138
karolgro Avatar answered Jan 02 '26 03:01

karolgro



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!