Toplam Gönderi:
72
Karma:
626
Katılım:
24.04.2010
yer:
Brazil
Howdy! How to get an instance of IOrderProcessingService inside a controlle? I need to check order status. Thanks! -Alberto
Toplam Gönderi:
72
Karma:
626
Katılım:
24.04.2010
yer:
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(); } } }
Toplam Gönderi:
16619
Karma:
155940
Katılım:
22.10.2008
yer:
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 } }
Toplam Gönderi:
17
Karma:
85
Katılım:
15.03.2011
yer:
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
MVP
Sertifikalı Geliştirici
Toplam Gönderi:
1168
Karma:
12695
Katılım:
15.11.2011
yer:
United States
Is this in a plugin or in the main code? You shouldn't have to register controllers individually.
Toplam Gönderi:
17
Karma:
85
Katılım:
15.03.2011
yer:
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.
MVP
Sertifikalı Geliştirici
Toplam Gönderi:
1168
Karma:
12695
Katılım:
15.11.2011
yer:
United States
It's not the "right" way because you can't unit test it.