Ninject and MVC2(Please help)
-
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 codeusing 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
-
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 codeusing 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
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..)
-
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 codeusing 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
I think the parameter "connectionString" of WithConstructorArgument must be the same with Constructor Argument of the class SqlProductRepository.