ninject mvc and asp.net mvc2 don't work on vwd express 2010

96 Views Asked by At

what's wrong with ninject mvc and asp.net mvc2 ? i have tried to set a simple project on vwd 2010 express but it seems that the ninject controller factory can't create controllers properly, this is my code

public class MvcApplication : Ninject.Web.Mvc.NinjectHttpApplication
{
    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            "Default", // Nom d'itinéraire
            "{controller}/{action}/{id}", // URL avec des paramètres
            new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Paramètres par défaut
        );

    }

    protected override void OnApplicationStarted()
    {            
        AreaRegistration.RegisterAllAreas();

        RegisterRoutes(RouteTable.Routes);
    }


    protected override IKernel CreateKernel()
    {
        return new StandardKernel(new ServiceModule());
    }

    #region Module d'injection de depandance

    internal class ServiceModule : NinjectModule
    {
        public override void Load()
        {
            Bind<IMyService>().To<MyServiceImpl>();
        }
    }

    #endregion
}

code of the controller

public class MyController : Controller
{
    private IMyService myService;

    public MyController(IMyService myService)
    {
        this.myService = myService;
    }


    public ActionResult Index()
    {
        return View();
    }
}

thanks in advance

1

There are 1 best solutions below

0
On

I solved the probleme, i forgot to set the binding for a DAO, so when ninject can't resolve the object graph it delegate the controller's creation to the default factory wich requires a parametreless constructor.