7.4.5 Creating the Product Repository; Listing 7-15. Adding the Real Repository Binding in the NinjectDependencyResolver.cs File; Fix typo in Web.config

chap07
Jason Zhu 2021-09-08 13:26:56 +10:00
parent 46fbd3ed91
commit 72064ff65c
2 changed files with 5 additions and 14 deletions

View File

@ -7,6 +7,7 @@ using System.Web.Services.Description;
using Moq; using Moq;
using Ninject; using Ninject;
using SportsStore.Domain.Abstract; using SportsStore.Domain.Abstract;
using SportsStore.Domain.Concrete;
using SportsStore.Domain.Entities; using SportsStore.Domain.Entities;
namespace SportsStore.WebUI.Infrastructure namespace SportsStore.WebUI.Infrastructure
@ -33,15 +34,7 @@ namespace SportsStore.WebUI.Infrastructure
private void AddBindings() private void AddBindings()
{ {
Mock<IProductRepository> mock = new Mock<IProductRepository>(); kernel.Bind<IProductRepository>().To<EFProductRepository>();
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));
} }

View File

@ -4,15 +4,13 @@
https://go.microsoft.com/fwlink/?LinkId=301880 https://go.microsoft.com/fwlink/?LinkId=301880
--> -->
<configuration> <configuration>
<connectionStrings>
<add name="EFDbContext" connectionString="Data Source=XLW-5CD034CWRC;
Initial Category=SportsStore;Integrated Security=True"
providerName="System.Data.SqlClient"/>
</connectionStrings>
<configSections> <configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --> <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections> </configSections>
<connectionStrings>
<add name="EFDbContext" connectionString="Data Source=XLW-5CD034CWRC;Initial Catalog=SportsStore;Integrated Security=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
<appSettings> <appSettings>
<add key="webpages:Version" value="3.0.0.0" /> <add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" /> <add key="webpages:Enabled" value="false" />