Всего сообщений:
72
Карма:
626
Присоединился:
24.04.2010
Страна:
Brazil
Howdy! How to get an instance of IOrderProcessingService inside a controlle? I need to check order status. Thanks! -Alberto
Всего сообщений:
72
Карма:
626
Присоединился:
24.04.2010
Страна:
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(); } } }
Всего сообщений:
16619
Карма:
155940
Присоединился:
22.10.2008
Страна:
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 } }
Всего сообщений:
17
Карма:
85
Присоединился:
15.03.2011
Страна:
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
Сертифицированный разработчик
Всего сообщений:
1168
Карма:
12695
Присоединился:
15.11.2011
Страна:
United States
Is this in a plugin or in the main code? You shouldn't have to register controllers individually.
Всего сообщений:
17
Карма:
85
Присоединился:
15.03.2011
Страна:
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
Сертифицированный разработчик
Всего сообщений:
1168
Карма:
12695
Присоединился:
15.11.2011
Страна:
United States
It's not the "right" way because you can't unit test it.