As instructed by the book, I have included the reference to System.Web in the directives of my ProductService class:
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
namespace ASPPatterns.Chap2.Service
{
public class ProductService
{
private ProductRepository _productRepository;
public ProductService()
{
_productRepository = new ProductRepository();
}
public IList<Product> GetAllProductsIn(int categoryId)
{
IList<Product> products;
string storageKey = string.Format("products_in_category_id_{0}", categoryId);
products = (List<Product>)System.Web.HttpContext.Current.Cache.Get(storageKey);
if (products == null)
{
products = _productRepository.GetAllProductsIn(categoryId);
HttpContext.Current.Cache.Insert(storageKey, products);
}
}
}
}
But the errors I'm getting are:
Code:
Error 1 The type or namespace name 'HttpContext' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)
and
Code:
Error 2 The name 'HttpContext' does not exist in the current context
Can anyone explain how I'm supposed to get the HttpContext class to work inside of a class library?
Thanks!
