I am having trouble with the pro asp.net mvc 3 framework book. On page 175 Creating the Product Repository.
I have errors: Error 1 ‘SportsStore.Domain.Concrete.EFProductRepository’ does not implement interface member ‘SportsStore.Domain.Abstract.IProductRepository.Products.set’
SportsStore\SportsStore.Domain\Concrete\EFProductRepository.cs 11 18 SportsStore.Domain
#
Error 2 The type or namespace name ‘Concrete’ does not exist in the namespace ‘SportsStore.Domain’\SportsStore.WebUI\Infrastructure\NinjectControllerFactory.cs 11 26 SportsStore.WebUI
This is my repository:
using System; using System.Collections.Generic;
using System.Linq;
using System.Text;
using SportsStore.Domain.Abstract;
using SportsStore.Domain.Entities;
//using System.Web;
namespace SportsStore.Domain.Concrete
{
public class EFProductRepository : IProductRepository
{
private EFDbContext context = new EFDbContext();
public IQueryable<Product> Products
{
get { return context.Products; }
}
}
}
My Product class which is public:
namespace SportsStore.Domain.Entities
{
public class Product
{
public int ProductID { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public decimal Price { get; set; }
public string Category { get; set; }
}
}
my interface:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using SportsStore.Domain.Entities;
namespace SportsStore.Domain.Abstract
{
public interface IProductRepository
{
IQueryable<Product> Products { get; set; }
}
}
My EFDBContext class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SportsStore.Domain.Entities;
using System.Data.Entity;
namespace SportsStore.Domain.Concrete
{
public class EFDbContext : DbContext
{
//DBset<type> Property name is Products
public DbSet<Product> Products { get; set; }
}
}
My ninjectcontrollerfactory class:
using System; using System.Collections.Generic;
using System.Linq; using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using Ninject;
using Moq;
using SportsStore.Domain.Abstract;
using SportsStore.Domain.Entities;
using SportsStore.Domain.Concrete;
namespace SportsStore.WebUI.Infrastructure
{
public class NinjectControllerFactory : DefaultControllerFactory
{
private IKernel ninjectKernel;
public NinjectControllerFactory()
{
ninjectKernel = new StandardKernel();
AddBindings();
}
protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
{
return controllerType == null ? null : (IController)ninjectKernel.Get(controllerType);
}
private void AddBindings()
{
//P163 - Add a mock implementation of the IProductRepository Interface
//Mock<IProductRepository> _mock = new Mock<IProductRepository>();
//_mock.Setup(m => m.Products).Returns(new List<Product>
//{
// new Product {Name = "Football",Price = 25},
// new Product {Name = "Surf Board",Price = 179},
// new Product {Name = "Running Shoes",Price = 95},
//}.AsQueryable());
//_ninjectKernel.Bind<IProductRepository>().ToConstant(_mock.Object);
ninjectKernel.Bind<IProductRepository>().To<EFProductRepository>(); //P176 Bind to our Live repository
}
}
}
There are 3 projects with references:
SportsStore.Domain
SportsStore.UnitTests = ref to Moq, Ninject,SportsStore.Domain, SportsStore.WebUI
SportsStore.WebUI = ref to Ninject,SportsStore.Domiain
I have search google and it says add a reference on the SportsStore.Domain project to the WebUI project but when i do this it says it cant because it will cause a circular dependency.
Error 1 and Error 2 above, I don’t understand because the interface is implemented and also the namespace is in the NinjectControllerFactory where I am binding the IProductRepository to the interface EFProductRepository
Thanks
Take the ‘set’ away from
and it should solve your problem