2011-04-01 25 views
0

ninject mvc和asp.net mvc2有什么问题?我试图设置VWD 2010快递一个简单的项目,但它似乎ninject控制器工厂不能正确地创建控制器,这是我的代码控制器ninject mvc和asp.net mvc2不能在vwd express 2010上工作

public class MyController : Controller 
{ 
    private IMyService myService; 

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


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

感谢

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 
} 

代码提前

+0

你能提供任何错误信息或任何我们继续? – 2011-04-01 21:31:12

+0

谢谢,当我运行该项目,我有一个错误,说'没有无参数构造函数找到MyController' – anouar 2011-04-01 21:36:37

回答

0

我解决了问题,我忘了为DAO设置绑定,所以当ninject无法解析对象图时,它将控制器的创建委托给默认工厂,这需要无参数构造函数。

相关问题