我有一个用 Lamar 设置的 dotnet 核心网站,我在 Startup.cs 中有以下方法
public void ConfigureContainer(ServiceRegistry services)
{
...
}
使用 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”不包含“AddInstances”的定义,并且找不到接受“ServiceRegistry.InstanceExpression”类型的第一个参数的可访问扩展方法“AddInstances”(您是否缺少 using 指令或程序集引用?)
services.For<IService>().AddInstances(x =>
{
...
});
这是在另一个命名空间中吗?根据示例,它是否仅存在于 StructureMap Registry 对象中,如果是,我如何从注入的 ServiceRegistry 中获取它?