Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Ninject and MVC2(Please help)

Ninject and MVC2(Please help)

Scheduled Pinned Locked Moved ASP.NET
helpasp-netcsharplinqsysadmin
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    future3839
    wrote on last edited by
    #1

    Hi, firstly, sorry if I post it for 2nd times. because its a week I stuck in this problem I am trying to build up my knowledge regarding ASP.Net and new things which I read from books. Frankly, its few days I got this error. after running my code I see this error No matching bindings are available, and the type is not self-bindable. Activation path: 2) Injection of dependency CommunityUserRepository into parameter _rep of constructor of type AccountController 1) Request for AccountController it is the source code

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    using Ninject.Core;
    using SportsStore;
    using SportsStore.WebUI.Controllers;
    using System.Web.Routing;
    using Ninject.Modules;
    using Ninject.Core.Modules;
    using SportsStore.Domain.Abstract;
    using System.Configuration;
    using SportsStore.Domain.Concrete;

    namespace SportsStore.WebUI.Infrastructure
    {
    public class NinjectControllerFactory : DefaultControllerFactory
    {
    // A Ninject "kernel" is the thing that can supply object instances
    private IKernel Kernel = new StandardKernel(new SportsStoreServices());

        // ASP.NET MVC calls this to get the controller for each request
        protected override IController GetControllerInstance(RequestContext context,Type controllerType)
        {
            //if (controllerType == null)
            //    return null;
            //return (IController)Kernel.Get(controllerType);
    
            return controllerType == null ? null
                                         : (IController)Kernel.Get(controllerType);
        }
    
        // Configures how abstract service types are mapped to concrete implementations
        private class SportsStoreServices : StandardModule
        {
            public override void Load()
            {
                //registered any IProductsRepository with the DI container.
                Bind<IProductRepository>().To<SqlProductRepository>().WithConstructorArgument
                    ("connectionString", ConfigurationManager.ConnectionStrings\["AppDb"\].ConnectionString);
                
            }
        }
    }
    

    }

    error occure in this line protected override IController GetControllerInstance(RequestContext context,Type controllerType) { //if (controllerType == null) // return null; //return (IController)Kernel.Get(controllerType); return controllerType == null ? null : (IController)Ker

    M S 2 Replies Last reply
    0
    • F future3839

      Hi, firstly, sorry if I post it for 2nd times. because its a week I stuck in this problem I am trying to build up my knowledge regarding ASP.Net and new things which I read from books. Frankly, its few days I got this error. after running my code I see this error No matching bindings are available, and the type is not self-bindable. Activation path: 2) Injection of dependency CommunityUserRepository into parameter _rep of constructor of type AccountController 1) Request for AccountController it is the source code

      using System;
      using System.Collections.Generic;
      using System.Linq;
      using System.Web;
      using System.Web.Mvc;
      using Ninject.Core;
      using SportsStore;
      using SportsStore.WebUI.Controllers;
      using System.Web.Routing;
      using Ninject.Modules;
      using Ninject.Core.Modules;
      using SportsStore.Domain.Abstract;
      using System.Configuration;
      using SportsStore.Domain.Concrete;

      namespace SportsStore.WebUI.Infrastructure
      {
      public class NinjectControllerFactory : DefaultControllerFactory
      {
      // A Ninject "kernel" is the thing that can supply object instances
      private IKernel Kernel = new StandardKernel(new SportsStoreServices());

          // ASP.NET MVC calls this to get the controller for each request
          protected override IController GetControllerInstance(RequestContext context,Type controllerType)
          {
              //if (controllerType == null)
              //    return null;
              //return (IController)Kernel.Get(controllerType);
      
              return controllerType == null ? null
                                           : (IController)Kernel.Get(controllerType);
          }
      
          // Configures how abstract service types are mapped to concrete implementations
          private class SportsStoreServices : StandardModule
          {
              public override void Load()
              {
                  //registered any IProductsRepository with the DI container.
                  Bind<IProductRepository>().To<SqlProductRepository>().WithConstructorArgument
                      ("connectionString", ConfigurationManager.ConnectionStrings\["AppDb"\].ConnectionString);
                  
              }
          }
      }
      

      }

      error occure in this line protected override IController GetControllerInstance(RequestContext context,Type controllerType) { //if (controllerType == null) // return null; //return (IController)Kernel.Get(controllerType); return controllerType == null ? null : (IController)Ker

      M Offline
      M Offline
      michaelschmitt
      wrote on last edited by
      #2

      Hi there, i'm no ninject expert im afraid - only did one mvp-windows-mobile project with it - so this may not be an answer.. ..but obviously, the ninject kernel cannot inject CommunityUserRepository while creating the controller instance. This usually means that no corresponding mapping has been loaded into the kernel inside "Load". So maybe, you have to include a mapping for CommunityUserRepository in the kernels load-method. Also, the constructor parameter "xyRepository" of your controller should maybe be an interface. (There may be other places for ninject interface/implementation bindings, i dont know..)

      1 Reply Last reply
      0
      • F future3839

        Hi, firstly, sorry if I post it for 2nd times. because its a week I stuck in this problem I am trying to build up my knowledge regarding ASP.Net and new things which I read from books. Frankly, its few days I got this error. after running my code I see this error No matching bindings are available, and the type is not self-bindable. Activation path: 2) Injection of dependency CommunityUserRepository into parameter _rep of constructor of type AccountController 1) Request for AccountController it is the source code

        using System;
        using System.Collections.Generic;
        using System.Linq;
        using System.Web;
        using System.Web.Mvc;
        using Ninject.Core;
        using SportsStore;
        using SportsStore.WebUI.Controllers;
        using System.Web.Routing;
        using Ninject.Modules;
        using Ninject.Core.Modules;
        using SportsStore.Domain.Abstract;
        using System.Configuration;
        using SportsStore.Domain.Concrete;

        namespace SportsStore.WebUI.Infrastructure
        {
        public class NinjectControllerFactory : DefaultControllerFactory
        {
        // A Ninject "kernel" is the thing that can supply object instances
        private IKernel Kernel = new StandardKernel(new SportsStoreServices());

            // ASP.NET MVC calls this to get the controller for each request
            protected override IController GetControllerInstance(RequestContext context,Type controllerType)
            {
                //if (controllerType == null)
                //    return null;
                //return (IController)Kernel.Get(controllerType);
        
                return controllerType == null ? null
                                             : (IController)Kernel.Get(controllerType);
            }
        
            // Configures how abstract service types are mapped to concrete implementations
            private class SportsStoreServices : StandardModule
            {
                public override void Load()
                {
                    //registered any IProductsRepository with the DI container.
                    Bind<IProductRepository>().To<SqlProductRepository>().WithConstructorArgument
                        ("connectionString", ConfigurationManager.ConnectionStrings\["AppDb"\].ConnectionString);
                    
                }
            }
        }
        

        }

        error occure in this line protected override IController GetControllerInstance(RequestContext context,Type controllerType) { //if (controllerType == null) // return null; //return (IController)Kernel.Get(controllerType); return controllerType == null ? null : (IController)Ker

        S Offline
        S Offline
        shinewu365
        wrote on last edited by
        #3

        I think the parameter "connectionString" of WithConstructorArgument must be the same with Constructor Argument of the class SqlProductRepository.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups