PaymentManager 类型的构造函数包含名称为 'paymentMethods' 且类型为 List 的参数,该参数未<IPaymentMethod>注册



我也收到下面的错误。 这是因为它不是列表吗,如果是,我该如何纠正?

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实例。

相关内容

最新更新