c# - PaymentManager 类型的构造函数包含名称为“paymentMethods”和类型为 List 的参数未注册的
问题描述
我也收到以下错误。这是因为它不是列表,如果是这样,我该如何纠正?
container.RegisterCollection<IPaymentMethod>(new[]
{
typeof(AuthorizeNetProvider),
typeof(StripeProvider),
typeof(PayPalProProvider),
typeof(PayPalStandardProvider),
typeof(IntuitProvider),
typeof(UsaEpayProvider),
typeof(ITransactProvider),
typeof(SecureNetProvider),
typeof(ExposurePayProvider),
typeof(PayTraceProvider),
typeof(BraintreeProvider)
});
错误
配置无效。创建 IDivisionsService 类型的实例失败。PaymentManager 类型的构造函数包含名为“paymentMethods”的参数和未注册的 List<IPaymentMethod> 类型。请确保 List<IPaymentMethod> 已注册,或更改 PaymentManager 的构造函数。
承包商
public PaymentManager(List<IPaymentMethod> paymentMethods)
{
_paymentMethods = paymentMethods;
}
解决方案
List<T>
目前不支持作为集合类型。将构造函数更改为以下之一:
IEnumerable<T>
IList<T>
ICollection<T>
IReadOnlyList<T>
IReadOnlyCollection<T>
- T[]
前 5 种类型具有以下行为:
- 它们表现为流,这意味着它们每次迭代时都会从容器中解析实例。
- 正因为如此,它们被注入为单例。然而,他们的情况仍然根据他们适当的生活方式得到解决。
- 它们是不可变的。尝试添加、更改或删除实例将会失败
IList<T>
并ICollection<T>
出现异常。
最后一种类型,数组,总是表示实例的副本,不会像流一样运行。因为它是一个可变的实例列表,所以数组总是被注入为Transient
,即使它的依赖列表都代表Singleton
实例。
推荐阅读
- python - 我应该如何处理包含大约 300000 个小数据表组的数据集?
- ssl - TLS 握手失败
- go - 列出模块的依赖项,而不是包
- android - 我的列表大小是整个屏幕,看不到下面的按钮或滚动
- python - 时间表不会显示
- facebook - 颤振:为 iOS 8.0 编译,但模块 'FBSDKCoreKit' 的最低部署目标为 iOS 9.0
- java - 使用 Thymeleaf 启动 CRUD 应用程序:接受视频类型
- javascript - react forEach 计算但不显示
- django - 在 django 中过滤后的分页
- c - 如何调整我的函数,以便我可以在一个函数内进行多次计算