0
votes

I am trying to access the productservice in my OrderService like below but it throws error

No parameterless constructor defined for this object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.MissingMethodException: No parameterless constructor defined for this object.

 //Many repositories are here just like 3 belows
 private readonly IRepository<Store> _storeRepository;  

 private readonly IRepository<ProductPicture> _productPictureRepository; 

 private readonly IRepository<Picture> _picture;  

 private readonly IProductService _productService; 

 //private readonly IProductService _productService = EngineContext.Current.Resolve<IProductService>();

   //tried above line but with no success
//Constructor for OrderService goes below
  public OrderService(IRepository<Store> storeRepository,
       IProductService productService
    )
    {
      _storeRepository = storeRepository;
        _productService= productService;
    }

If I remove reference for productService, application works well. I searched alot on web and on nopcommerce forum, but didnt find any solutions.

Any help?

1
Try putting a empty constructor like this ´public OrderService() { }´, let me know - Guillermo Oramas R.
Is this your OrderService or are you modifying the nop one? It's possible that something in a dependency further up the chain from IProductService has a dependency on IOrderService, creating a circular reference that usually throws the error you are seeing. - AndyMcKenna
Its orderservice from nop only and i have changed lot since in it - Nitin Varpe

1 Answers

2
votes

The issue is that the implementation for IProductService does not provided a parameterless contructor, or public ProductServiceImpl() { } and thus it cannot be resolved by the dependency injection framework.

When you register IProductService make sure you specify a constructor to use or create an empty one for the registered implementation.