Lamar AddInstances 与 ServiceRegistry

Lamar AddInstances with ServiceRegistry

我有一个使用 Lamar 的 dotnet 核心网站设置,我在 Startup.cs

中有以下方法
public void ConfigureContainer(ServiceRegistry services)
{
  ...
}

我想按照 https://jasperfx.github.io/lamar/documentation/ioc/registration/registry-dsl/

的文档中的说明使用 AddInstances()

使用 For().AddInstances() 添加多个注册

// registry is a StructureMap Registry object
registry.For<IService>().AddInstances(x =>
{
    // Equivalent to For<IService>().Add<ColorService>().....
    x.Type<ColorService>().Named("Red").Ctor<string>("color").Is("Red");

    // Equivalent to For<IService>().Add(new ColorService("Yellow"))......
    x.Object(new ColorService("Yellow")).Named("Yellow");

    // Equivalent to For<IService>().Use(() => new ColorService("Purple"))....
    x.ConstructedBy(() => new ColorService("Purple")).Named("Purple");

    x.Type<ColorService>().Named("Decorated").Ctor<string>("color").Is("Orange");
});

但是,AddInstances() 不存在,我得到以下错误

'ServiceRegistry.InstanceExpression' does not contain a definition for 'AddInstances' and no accessible extension method 'AddInstances' accepting a first argument of type 'ServiceRegistry.InstanceExpression' could be found (are you missing a using directive or an assembly reference?)

services.For<IService>().AddInstances(x =>
{
 ...

 });

这是在另一个命名空间中吗?根据示例,它是否仅存在于 StructureMap Registry 对象上,如果是,我如何从注入的 ServiceRegistry 中获取它?

我想这个方法已经被弃用了,你可以简单地做...

services.For<IService>().Add<Service1>().Named("1");
services.For<IService>().Add<Service2>().Named("2");