Nitin S
Nitin S

Reputation: 7598

Unable to create instance of NopEngine

I am creating a new theme in nopcommerce,
I want to print all categories in view,

I have wrote follwing code to retrieve all subcategories within a cartegory,
This call(on line 2) fails with Object reference not set to instance of onject error.

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

Upvotes: 2

Views: 171

Answers (1)

Andrei M
Andrei M

Reputation: 3439

You should use the following code to resolve ICategoryService:

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

Do not forget to add appropriate "using" directives

Upvotes: 4

Related Questions