I am working through the Book "Pro ASP.NET MVC 5 - Adam Freeman ' . In chapter 7 the Sportstore application is built and the Products are first displayed with the Mock Repository on page 174. Everything works fine up to here. Adding the Mock IProductRepository Implementation in the NinjectDependencyResolver.cs . Here is the AddBindings method.
private void AddBindings()
{
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 }
});
kernel.Bind<IProductRepository>().ToConstant(mock.Object);
}
After setting up the database and Entity Framework, Adding the Real Repository Binding in the NinjectDependencyResolver.cs , the method looks like this - as on page 182
private void AddBindings()
{
kernel.Bind<IProductRepository>().To<EFProductRepository>();
}
When I run it now, it displays nothing, so I am assuming that the data is not found. I have already redone this chapter 3 times and no luck. I do not know where to look next, please help!
Any help will be highly appreciated!
I've got the same issue... But the solution was quite simple. I just added "connectionStrings" to the wrong web.config-file...
There are two: one in SportsStore.WebUI root and the other one in SportsStore.WebUI/Views...
Just add the connectionStrings to the root-web.config and you'll see all records from your database in List.cshtml...