问题描述
伊夫到处搜寻,我似乎无法找到一种方法,在我的项目实施ninject。香港专业教育学院听到推导MvcApplication到NinjectHttpApplication的。但NinjectHttpApplication心不是发现即使我的lib添加到引用。我找不到Ninject.Web.Mvc。有没有人有一个引导,以使这项工作的地方,我想要做的是能到我的接口从我的域名到现有的实现绑定。
Ive searched everywhere, i can't seem to find a way to implement ninject in my project. Ive heard of deriving MvcApplication to the NinjectHttpApplication. But NinjectHttpApplication isnt found even if i add the lib to the reference. I can't find Ninject.Web.Mvc. Does anyone have a guide somewhere in order to make this work, all i want to do is be able to bind my interface from my domain to existing implementation.
推荐答案
http://weblogs.asp.net/shijuvarghese/archive/2010/04/30/dependency-injection-in-nerddinner-app-using-ninject.aspx
看起来像它的大部分是通过
Looks like the bulk of it is done via
Global.asax.cs
public class MvcApplication : NinjectHttpApplication
替换的Application_Start
与
protected override void OnApplicationStarted()
{
AreaRegistration.RegisterAllAreas();
RegisterRoutes(RouteTable.Routes);
ViewEngines.Engines.Clear();
ViewEngines.Engines.Add(new MobileCapableWebFormViewEngine());
RegisterAllControllersIn(Assembly.GetExecutingAssembly());
}
然后创建Ninject模块和配置内核,都在博客文章和源$ C $ C解释可以在这里找到:的
虽然以上为MVC 2,它仍然应该应用
While the above is for MVC 2, it should still apply
这篇关于我如何使用Ninject 2在ASP.NET MVC 3应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!