升级到Ninject 3.0.0-rc3后的连接字符串异常 [英] Connection string exception after upgrading to Ninject 3.0.0-rc3

查看:95
本文介绍了升级到Ninject 3.0.0-rc3后的连接字符串异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近将我的网站项目更新为Ninject 3.0.0-rc3,此后我收到以下错误消息:所提供的连接无效,因为它包含的映射或元数据信息不足." 当我使用版本2.2.0.0时,所有这些都有效.

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?

我正在使用EF,后端是SQL Server 2008 R2.

I am using EF and my backend is SQL Server 2008 R2.

推荐答案

我遇到了同样的问题,并且通过改回扩展NinjectHttpApplication而不是NinjectWebCommon.cs方法来解决此问题.参见 https://github.com/ninject/ninject.web.mvc/wiki/Setting-up-an-MVC3-application (更多信息).

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.

为了使Ninject 3升级正常工作,我必须在绑定模块中添加以下绑定:

In order for the Ninject 3 upgrade to work, I had to add the following bindings to my binding modules:

        Bind<Func<IKernel>>().ToMethod(ctx => () => new Bootstrapper().Kernel);
        Bind<IHttpModule>().To<HttpApplicationInitializationHttpModule>();

我认为问题的根源在于NinjectWebCommon.cs在应用程序完全了解其自身上下文之前被调用,因此,如果将上下文实例化为连接的一部分,则Entity Framework无法弄清楚如何解析连接字符串.设置绑定.对于许多项目而言,这不是问题,但是我们的数据库使用数据库配置来确定首先要加载的Ninject模块. Global的Application_Start方法大概是在应用程序生命周期的某个稍后时刻被调用的,因此在Global中设置绑定就可以了.

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.

这篇关于升级到Ninject 3.0.0-rc3后的连接字符串异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆