2014-09-04 83 views
1

我正在使用nop商務。爲此對象定義的無參數構造函數-nop commerce 2.6

我向Catalog Controller添加一個新的服務類。

然後它得到這個錯誤。

No parameterless constructor defined for this object. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.MissingMethodException: No parameterless constructor defined for this object. 

Source Error: 


Line 3: @foreach (var widget in Model) 
Line 4: { 
Line 5:  @Html.Action(widget.ActionName, widget.ControllerName, widget.RouteValues) 
Line 6: } 


Source File: f:\project\sitename\Presentation\Nop.Web\Views\Widget\WidgetsByZone.cshtml Line: 5 

我改變了這個控制器。

public CatalogController(ICategoryService categoryService, 
      IManufacturerService manufacturerService) 

public CatalogController(ICategoryService categoryService, 
      IManufacturerService manufacturerService, IbookService bookService) 

,它已收到錯誤。

如何解決?

+2

這看起來就像您未註冊IProductService接口時會遇到的那種錯誤。你是否正確地註冊了你的類型? – Carth 2014-09-04 02:58:42

回答

3

如果你在這裏使用的IProductService是原始的nopCommerce IProductService,我沒有找到它會拋出錯誤的原因。但是,如果它是您自己寫的服務,那麼您需要在DependencyRegistrar.cs中註冊它。您可以在nopCommerce中查找當前的示例,瞭解如何註冊您自己的依賴關係。 :)

1

如果您在ProductService或其任何導致其中一個無法加載的相關性中進行了更改,也會發生這種情況。註釋掉ProductService構造函數中的參數,如果它有效,則取消每個參數的註釋,直到再次分解爲止。我不知道有更好的方法來找出哪個服務是問題。

相關問題