regusman wrote:I'm writing a small program which adds products (and variants) in batch. So I found the function "InsertProduct" in de ProductService-class. How should I declare a Prdouctservice instance ?
This is what I'm doing now:
ProductService ps = new ProductService();
ps.InsertProduct(product);
This doesn't work, because the constructor for the ProductService doensn't allow 0 arguments. I need about 20 arguments...
Isn't there an easier way to do this ?
Just use Dependency Injection to do the job:
public class [YOUR_CLASS]
{
private readonly IProductService _productService;
public [YOUR_CLASS](IProductService productService)
{
_productService = productService;
}
}
The code above does the following:
- declare a private field of type IProductService
- create a constructor that takes in IProductService
- maps the argument in the constructor to the private field
- nopCommerce will take care of the rest (i.e. resolving the dependencies)
General Rule of Thumb (correct for 90% of the time): If you have a service named [NAME]Service, then you'll have an interface I[NAME]Service, and vice versa. :)