The constructor of type PaymentManager contains the parameter with name 'paymentMethods' and type List<IPaymentMethod> that is not registered

ε祈祈猫儿з 提交于 2019-12-11 17:12:22

问题


I am also getting the error below. Is this because its not a List, and if so how do I correct this?

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)
});

Error

The configuration is invalid. Creating the instance for type IDivisionsService failed. The constructor of type PaymentManager contains the parameter with name 'paymentMethods' and type List<IPaymentMethod> that is not registered. Please ensure List<IPaymentMethod> is registered, or change the constructor of PaymentManager.

Contructor

public PaymentManager(List<IPaymentMethod> paymentMethods)
{
    _paymentMethods = paymentMethods;
}

回答1:


List<T> is currently not supported as collection type. Change the constructor to one of the following:

  • IEnumerable<T>
  • IList<T>
  • ICollection<T>
  • IReadOnlyList<T>
  • IReadOnlyCollection<T>
  • T[]

The first 5 types have the following behavior:

  • They behave as streams, meaning that they resolve instances from the container, every time they are iterated.
  • Because of this, they are injected themselves as singletons. Their instances, however, are still resolved according to their appropriate lifestyle.
  • They are immutable. Trying to add, change or remove instances from IList<T> and ICollection<T> will fail with an exception.

The last type, the array, always represent a copy of instances and will not behave as a stream. Because it is a mutable list of instances, array is always injected as Transient, even though its list of dependencies all represent Singleton instances.



来源:https://stackoverflow.com/questions/50166383/the-constructor-of-type-paymentmanager-contains-the-parameter-with-name-payment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!