Ninject与MVC3 RTM [英] Ninject with MVC3 RTM
问题描述
我已经升级,从RC2 MVC3到RTM。我们使用Ninject 2.1.0.76,但一旦我升级事情停止工作。所以我用的NuGet经理以获取最新的Ninject,Ninject.MVC3和Ninject.Web.Mvc库(2.1.0.91,1.0.0.0和2.1.0.39分别)。现在,它创建了一个AppStart_NinjectMVC3文件。
I've upgraded MVC3 from RC2 to RTM. We were using Ninject 2.1.0.76, but things stopped working once I upgraded. So I used the NuGet manager to get the latest Ninject, Ninject.MVC3 and Ninject.Web.Mvc libraries (2.1.0.91, 1.0.0.0 and 2.1.0.39 respectively). Now, it creates an AppStart_NinjectMVC3 file.
我从我的Global.asax删除NinjectHttpApplication并使它回到一个常规的HttpApplication。当我试图打造,我得到;
I removed NinjectHttpApplication from my global.asax and made it back into a regular HttpApplication. When I tried to build, I get;
异常被抛出由调用的目标
"Exception has been thrown by the target of an invocation"
进一步看,如果我禁用以下行;
Looking further, if I disable the following line;
DependencyResolver.SetResolver(新NinjectServiceLocator(内核));
DependencyResolver.SetResolver(new NinjectServiceLocator(kernel));
构建经历。但我pretty肯定我不想这样做。
The build goes through. But I'm pretty sure I don't want to do this.
任何想法?
-----更新---------
----- UPDATE ---------
我创建了一个新的项目MVC3,增加了参考Ninject.MVC3这个构建并运行良好。我比较web.config中,没有看到,涉及到Ninject或MVC两个任何差异。一个新鲜的项目不加Ninject.Web.Mvc库,所以我删除,并注释掉与所有code,仍然,出现错误。
I created a new MVC3 project, added the reference to Ninject.MVC3 and this builds and runs fine. I compared web.config, don't see any differences that relate to Ninject or MVC in the two. A fresh project doesn't add the Ninject.Web.Mvc library, so I removed it and commented out all code relating to that, and still, the error occurs.
推荐答案
由于ASP.NET MVC 3 Beta版的 IServiceLocator
接口的是的 -us /库/ system.web.mvc.idependencyresolver%28VS.98%29.aspx相对=nofollow> 的IDependencyResolver
。我不知道Ninject.MVC3已经在那里他们实现了这个接口的版本。
Since ASP.NET MVC 3 Beta the IServiceLocator
interface is replaced by IDependencyResolver
. I'm not sure Ninject.MVC3 already has a release where they have implemented this interface.
从线路来看 DependencyResolver.SetResolver(新NinjectServiceLocator(内核))
他们似乎没有。
Judging from the line DependencyResolver.SetResolver(new NinjectServiceLocator(kernel))
it appears they have not.
这里一个简单的实现这个接口对Ninject的。
Here's a simple implementation of this interface for Ninject.
更新:在 Ninject.Web.Mvc
库有<一个href=\"https://github.com/ninject/ninject.web.mvc/blob/master/mvc3/src/Ninject.Web.Mvc/NinjectDependencyResolver.cs\"相对=nofollow> NinjectDependencyResolver
从的IDependencyResolver
接口扩展类。我认为你应该使用这个(我做的一切工作正常)。
UPDATE: The Ninject.Web.Mvc
library has a NinjectDependencyResolver
class that extends from the IDependencyResolver
interface. I think you should use this one (I do and everything works fine).
这篇关于Ninject与MVC3 RTM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!