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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With