问题
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.
回答1:
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:
Bind<Func<IKernel>>().ToMethod(ctx => () => new Bootstrapper().Kernel);
Bind<IHttpModule>().To<HttpApplicationInitializationHttpModule>();
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.
来源:https://stackoverflow.com/questions/9267065/connection-string-exception-after-upgrading-to-ninject-3-0-0-rc3