升级到 Ninject 3.0.0-rc3 后连接字符串异常
我最近将我的网站项目更新为 Ninject 3.0.0-rc3,之后我收到错误消息“提供的连接无效,因为它包含的映射或元数据信息不足”。 当我使用 2.2.0.0 版本时,所有这些都有效。
知道什么会导致出现此异常以及如何解决它?
我使用的是 EF,后端是 SQL Server 2008 R2。
I recently updated my web site project to Ninject 3.0.0-rc3 and after that I am getting the errors saying "The supplied connection is not valid because it contains insufficient mapping or metadata information."
All of this was working when I was using Version 2.2.0.0.
Any idea what would have caused this exception to show up and also how can I resolve it?
I am using EF and my backend is SQL Server 2008 R2.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

我遇到了同样的问题,我通过切换回扩展
NinjectHttpApplication
而不是 NinjectWebCommon.cs 方法来修复它。请参阅 https://github.com/ninject/ ninject.web.mvc/wiki/Setting-up-an-MVC3-application 了解更多详细信息。为了使 Ninject 3 升级正常工作,我必须将以下绑定添加到我的绑定模块中:
我认为问题的根源在于 NinjectWebCommon.cs 在应用程序完全了解其自己的上下文之前被调用,因此 Entity Framework如果在设置绑定过程中实例化了上下文,则无法弄清楚如何解析连接字符串。对于许多项目来说这不是问题,但我们的项目使用数据库配置来确定首先加载哪些 Ninject 模块。 Global 的
Application_Start
方法大概会在应用程序生命周期的稍后某个时刻被调用,因此在 Global 中设置绑定效果很好。I had the same issue, and I fixed it by switching back to extending
NinjectHttpApplication
rather than the NinjectWebCommon.cs approach. See https://github.com/ninject/ninject.web.mvc/wiki/Setting-up-an-MVC3-application for more details.In order for the Ninject 3 upgrade to work, I had to add the following bindings to my binding modules:
I think the root of the problem is that NinjectWebCommon.cs gets invoked before the application is fully aware of its own context, so Entity Framework can't figure out how to parse the connection strings if a context is instantiated as part of setting up your bindings. This wouldn't be an issue for many projects, but ours uses database configuration to determine which Ninject modules to load in the first place. Global's
Application_Start
method presumably gets invoked at some later point in the application's lifecycle, so setting up bindings in Global works just fine.