我使用: -如何使用asp.net mvc 2獲得ninject 2.0?
- asp.net的MVC RC 2
- Ninject和ninject asp.net mvc的擴展名(http://github.com/enkari/ninject.web.mvc)
我不斷收到此定義的「無參數的構造函數目的。'爲我的AccountController。 AccountController注入了服務。 ServiceModule中定義了這些服務的綁定。
在Global.asax.cs中查找我的MvcApplication代碼。
public class MvcApplication : NinjectHttpApplication // System.Web.HttpApplication
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Account", action = "Login", id = "" } // Parameter defaults
);
}
protected override void OnApplicationStarted()
{
AreaRegistration.RegisterAllAreas();
RegisterRoutes(RouteTable.Routes);
RegisterAllControllersIn(Assembly.GetExecutingAssembly());
}
protected override IKernel CreateKernel()
{
return new StandardKernel(new INinjectModule[] {
new ServiceModule(),
});
}
}
是工作的其他控制器?您是否針對ASP.NET MVC 2 RC 2構建了Ninject.Web.Mvc項目? – Charlino 2010-02-11 20:57:53
@Charlino。謝謝你的工作。 – 2010-02-12 02:26:23