Inject NopObjectContext to constructor of service classes

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
13 年 前
Hi,
I read the code of 1.9 version but I have no clue how to inject NopObjectContext in service class constructors? or on the other hand in witch section of code (or witch class) NopCommerce has specified inject NopObjectContext  to  service class constructors?

Thanks in advance
13 年 前
Ok,
It seams Unity Makes new instance of constructor's parameters and Invokes constructor.
13 年 前
Yeh, what I've been using has been:

var customerService = IoC.Resolve<ICustomerService>();

.. and if I want an instance of NopObjectContext, ..

var dbContext = IoC.Resolve<NopObjectContext>();

.. which keeps me from having to add the weird edmx connection string prefixes and the like.
13 年 前
stimpy77 wrote:
Yeh, what I've been using has been:

var customerService = IoC.Resolve<ICustomerService>();

.. and if I want an instance of NopObjectContext, ..

var dbContext = IoC.Resolve<NopObjectContext>();

.. which keeps me from having to add the weird edmx connection string prefixes and the like.


Thanks man.
13 年 前
I am trying to use your code in order to get list of all categories but it gives me an exception

var dbContext = IoC.Resolve<NopObjectContext>();

Object reference not set to an instance of an object
13 年 前
add these two line b4 making a call....

NopConfig.Init();
IoC.InitializeWith(new DependencyResolverFactory());

Enjoy!
13 年 前
I have the following code but am getting an error during Resolve

        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)
13 年 前
is this code in ur seprate module or inside nopCommerce??
13 年 前
Totally separate project that lives outside of NOP. I'm trying to make my service decoupled from the core framework.
13 年 前
If your service is RESTFUL service then it will not work...of it is standard web service....then thers is one section in web named....nopconfig (dnt remember the exact name as i dnt have source code with me right)....u jst need to include that section in ur project web.config....or jst copy the same connection string in ur project....i mean connection string in NopCommerce web site......
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.