我也收到下面的错误。 这是因为它不是列表吗,如果是,我该如何纠正?
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
的参数,该参数未注册。请确保 List 已注册,或更改 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
实例。