c# - 无法创建 NopEngine 实例

标签 c# asp.net asp.net-mvc nopcommerce

我正在 nopcommerce 中创建一个新主题,
我想打印 View 中的所有类别,

我编写了以下代码来检索类别中的所有子类别,
此调用(第 2 行)失败,并出现对象引用未设置为 onject 的实例错误。

var _engine = new NopEngine();
var categoryService = _engine.Resolve<ICategoryService>();
var L1Categories = from p in categoryService.GetAllCategoriesByParentCategoryId(24)
                    where (p.Deleted==false)
                    select p;

最佳答案

您应该使用以下代码来解析 ICategoryService:

var categoryService = EngineContext.Current.Resolve<ICategoryService>();

不要忘记添加适当的“using”指令

关于c# - 无法创建 NopEngine 实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32412228/

相关文章:

c# - PayPal IPN - 发送链接以支付金额?

c# - 我无法在 Team Foundation Server 上进行预测

asp.net-mvc - 发送kendoGrid参数(过滤器,排序)以进行文件下载

.net - 当需要进行模拟和单元测试时,如何抛出 SqlException?

asp.net - div继承父级不透明度

javascript - 我如何解析从模型传输到 JavaScript 的日期值?

c# - 此站点无法提供来自 dotnet linux 的安全连接 asp.net core

c# - 通过 LINQ 查询显示,不重复

c# - 在 C# 中,如何根据在 gridview 行中单击的按钮引用特定产品记录

asp.net - 在集成模式下替换 HttpContext.Current.Request.ServerVariables ["SERVER_NAME"]