I have modified my code after reading a few posts to the following: but I'm getting the error mentioned bellow.
public void InsertProducts()
{
Product OP = new Product();
OP.Name = "Bla";
OP.ShortDescription = "efwfewf";
NopConfig.Init();
IoC.InitializeWith(new DependencyResolverFactory());
var oPSvc = IoC.Resolve<IProductService>();
oPSvc.InsertProduct(OP);
}
Resolution of the dependency failed, type = "NopSolutions.NopCommerce.BusinessLogic.Products.IProductService", name = "(none)".
Exception occurred while: while resolving.
Exception is: InvalidOperationException - The type NopObjectContext has multiple constructors of length 1. Unable to disambiguate.
-----------------------------------------------
At the time of the exception, the container was:
Resolving NopSolutions.NopCommerce.BusinessLogic.Products.ProductService,(none) (mapped from NopSolutions.NopCommerce.BusinessLogic.Products.IProductService, (none))
Resolving parameter "context" of constructor NopSolutions.NopCommerce.BusinessLogic.Products.ProductService(NopSolutions.NopCommerce.BusinessLogic.Data.NopObjectContext context)
Resolving NopSolutions.NopCommerce.BusinessLogic.Data.NopObjectContext,(none)
public void InsertProducts()
{
Product OP = new Product();
OP.Name = "Bla";
OP.ShortDescription = "efwfewf";
NopConfig.Init();
IoC.InitializeWith(new DependencyResolverFactory());
var oPSvc = IoC.Resolve<IProductService>();
oPSvc.InsertProduct(OP);
}
Resolution of the dependency failed, type = "NopSolutions.NopCommerce.BusinessLogic.Products.IProductService", name = "(none)".
Exception occurred while: while resolving.
Exception is: InvalidOperationException - The type NopObjectContext has multiple constructors of length 1. Unable to disambiguate.
-----------------------------------------------
At the time of the exception, the container was:
Resolving NopSolutions.NopCommerce.BusinessLogic.Products.ProductService,(none) (mapped from NopSolutions.NopCommerce.BusinessLogic.Products.IProductService, (none))
Resolving parameter "context" of constructor NopSolutions.NopCommerce.BusinessLogic.Products.ProductService(NopSolutions.NopCommerce.BusinessLogic.Data.NopObjectContext context)
Resolving NopSolutions.NopCommerce.BusinessLogic.Data.NopObjectContext,(none)
hopefully this helps
http://stackoverflow.com/questions/1696326/unity-passing-in-a-new-datacontext-each-time
it's not the same context of the error, but the solution they provide (top voted answer) should get you in the right direction.