c# - 带有 ServiceRegistry 的 Lamar AddInstances
问题描述
我有一个用 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 中获取它?
解决方案
我猜该方法已被弃用,因为您可以简单地做......
services.For<IService>().Add<Service1>().Named("1");
services.For<IService>().Add<Service2>().Named("2");
推荐阅读
- c++11 - CUDA:如何使用 barrier.sync
- python - 从 HTML 获取链接(Selenium 和 Python)
- c# - 升级到 asp.net core 2.2 后的空 href
- three.js - 如何在 WEBGL 中使用 gl_LastFragData?
- javascript - 在 d3v4 的 scalelog 中使用来自 JSON 数据的日期
- java - 通过 Java Socket 和 ServerSocket 类连接到服务器
- apache-spark - RDD和传统的关系数据库系统有什么区别
- python - tensorflow Object_Detection 通过model_main.py训练,出现TypeError
- asp.net - 为什么我应该在 Web 配置中使用 customErrors 模式“关闭”?
- ios - 在 CollectionView 中解码时出现 JSON 解码器错误