开发者

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

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 pa开发者_StackOverflow中文版ramè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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜