【问题标题】:Lamar alternative to StructureMap Forward()StructureMap Forward() 的 Lamar 替代方案
【发布时间】:2021-02-05 16:59:09
【问题描述】:

在 StructureMap 中,您可以声明一个 Forward<,> 语句,这将允许注册单个具体实例以由来自 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>();

我正在考虑迁移到 Lamar,它是 StructureMap 的替代品,但我在注册选项中没有看到任何与此匹配的内容。

这在拉马尔可能吗?

【问题讨论】:

    标签: structuremap lamar


    【解决方案1】:

    根据StructureMap documentation 语法一直让用户感到困惑,建议的替换是:

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

    所以我建议使用这种 lambda 方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-06-13
      • 2015-03-03
      • 2015-09-25
      • 2019-12-16
      • 2011-06-20
      • 2015-11-03
      • 2014-04-03
      相关资源
      最近更新 更多