2011-04-01 71 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無法解析對象圖時,它將控制器的創建委託給默認工廠,這需要無參數構造函數。