Total Posts:
72
Karma:
626
Joined:
4/24/2010
Location:
Brazil
Howdy! How to get an instance of IOrderProcessingService inside a controlle? I need to check order status. Thanks! -Alberto
Total Posts:
72
Karma:
626
Joined:
4/24/2010
Location:
Brazil
I didnt get the point. Could you provide some sample code of how to do that? Thanks! My Code: public class MyRandomController : BaseNopController, IDependencyRegistrar { [HttpPost] public ActionResult MyAction(FormCollection model) { //Order Instance } public void Register(Autofac.ContainerBuilder builder, Core.Infrastructure.ITypeFinder typeFinder) { } public int Order { get { throw new NotImplementedException(); } } }
Total Posts:
16611
Karma:
155810
Joined:
10/22/2008
Location:
Armenia
Just have a look at any other controller and its constructor public class MyRandomController : BaseNopController { private readonly IOrderProcessingService _opvService; MyRandomController(IOrderProcessingService opvService) { this._opvService = opvService; } [HttpPost] public ActionResult MyAction(FormCollection model) { //Order Instance - opvService } }
Total Posts:
17
Karma:
85
Joined:
3/15/2011
Location:
United States
I tried the above to add a new custom controller, but I get a 'No parameterless constructor defined for this object' error when trying to load the controller. I tried adding the following code to the DependencyRegistrar in Nop.Web.Infrastructure, but still same error. builder.RegisterType<ProductsController>() .WithParameter(ResolvedParameter.ForNamed<ICacheManager>("nop_cache_static")); What else do we need to do do add a custom controller? My custom controller is based on the CatalogController, same constructor and fields. Thanks
Total Posts:
1168
Karma:
12695
Joined:
11/15/2011
Location:
United States
Is this in a plugin or in the main code? You shouldn't have to register controllers individually.
Total Posts:
17
Karma:
85
Joined:
3/15/2011
Location:
United States
This was in the main code, Web. I got around it by having a constructorless parameter and then using the dependency resolver to resolve each service that i would need: this._categoryService = DependencyResolver.Current.GetService<ICategoryService>(); this._productService = DependencyResolver.Current.GetService<IProductService>(); Not sure if this could cause problems but it works for now.
Total Posts:
1168
Karma:
12695
Joined:
11/15/2011
Location:
United States
It's not the "right" way because you can't unit test it.