title: No matching bindings are available, and the type is not self-bindable. Error activating IProductsRepository
body: <p>I am trying to learn MVC and I started out with the book <em>Pro ASP.NET MVC by Adam Freeman (5th edition @2013)</em>. </p>
  
  <p>In chapter VII I'm trying to follow the example in the book making a small app. </p>
  
  <p>The app fails to load after setting it up and trying to load a list of products. </p>
  
  <p>I'm trying to create a mock implementation of the abstract repository <em>IProductRepository</em> and have <em>Ninject</em> return the mock object whenever it gets a request for an implementation of the <em>IProductRepository</em> interface. </p>
  
  <p>I've searched and looked over other questions/ answers and found nothing that could help solve my problem and let me move forward with studying. This may be basic stuff but I really want to know what and why is not working as it should. </p>
  
  <pre><code>    public static class NinjectWebCommon 
      {
          private static readonly Bootstrapper bootstrapper = new Bootstrapper();
  
          /// &lt;summary&gt;
          /// Starts the application
          /// &lt;/summary&gt;
          public static void Start() 
          {
              DynamicModuleUtility.RegisterModule(typeof(OnePerRequestHttpModule));
              DynamicModuleUtility.RegisterModule(typeof(NinjectHttpModule));
              bootstrapper.Initialize(CreateKernel);
          }
  
          /// &lt;summary&gt;
          /// Stops the application.
          /// &lt;/summary&gt;
          public static void Stop()
          {
              bootstrapper.ShutDown();
          }
  
          /// &lt;summary&gt;
          /// Creates the kernel that will manage your application.
          /// &lt;/summary&gt;
          /// &lt;returns&gt;The created kernel.&lt;/returns&gt;
          private static IKernel CreateKernel()
          {
              var kernel = new StandardKernel();
              kernel.Bind&lt;Func&lt;IKernel&gt;&gt;().ToMethod(ctx =&gt; () =&gt; new Bootstrapper().Kernel);
              kernel.Bind&lt;IHttpModule&gt;().To&lt;HttpApplicationInitializationHttpModule&gt;();
  
              RegisterServices(kernel);
              return kernel;
          }
  
          /// &lt;summary&gt;
          /// Load your modules or register your services here!
          /// &lt;/summary&gt;
          /// &lt;param name="kernel"&gt;The kernel.&lt;/param&gt;
          private static void RegisterServices(IKernel kernel)
          {
              DependencyResolver.SetResolver(new NinjectDependencyResolver(kernel));
          }        
      }
  }
  </code></pre>
  
  <p>This next is my NinjectDependencyResolver class:</p>
  
  <pre><code>   public class NinjectDependencyResolver : IDependencyResolver
      {
  
          private IKernel kernel;
  
          [Inject]
          public NinjectDependencyResolver(IKernel kernelParam)
          {
              kernel = kernelParam;
              AddBindings();
          }
  
  
          public object GetService(Type serviceType)
          {
              return kernel.TryGet(serviceType);
          }
  
          public IEnumerable&lt;object&gt; GetServices(Type serviceType)
          {
              return kernel.GetAll(serviceType);
          }
  
  
          private void AddBindings()
          {
              var mock = new Mock&lt;IProductsRepository&gt;();
  
              mock.Setup(m =&gt; m.Products).Returns(new List&lt;Product&gt;
              {
                  new Product { Name = "Fotball", Price = 25 },
                  new Product { Name = "Surf Board", Price = 45 },
                  new Product { Name = "Running Shoes", Price = 95 }
              });
  
              kernel.Bind&lt;IProductsRepository&gt;().ToConstant(mock.Object);
          }
      }
  </code></pre>
  
  <p>And this is my controller class:</p>
  
  <pre><code>public class ProductController : Controller
  {
  
  
      private IProductsRepository repository;
  
  
  
      public ProductController(IProductsRepository productRepository)
      {
          repository = productRepository;
      }
  
  
  
      public ViewResult List()
      {
          return View(repository.Products);
      }
  </code></pre>
  
  <p>The error I get is the following:   </p>
  
  <p><em>Error activating IProductsRepository<br>
  No matching bindings are available, and the type is not self-bindable.<br>
  Activation path:<br>
   2) Injection of dependency IProductsRepository into parameter productRepository of constructor of type ProductController.<br>
   1) Request for ProductController.<br>
  Suggestions:<br>
   1) Ensure that you have defined a binding for IProductsRepository.<br>
   2) If the binding was defined in a module, ensure that the module has been loaded into the kernel.<br>
   3) Ensure you have not accidentally created more than one kernel.<br>
   4) If you are using constructor arguments, ensure that the parameter name matches the constructors parameter name.<br>
   5) If you are using automatic module loading, ensure the search path and filters are correct.</em>  </p>