无法在 Nuget 中将 Ninject 升级到最新版本 [英] Cannot upgrade Ninject to latest version in Nuget

查看:22
本文介绍了无法在 Nuget 中将 Ninject 升级到最新版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用一些 Ninject 包的 ASP.NET WebForms 应用程序,但我被困在某个版本上.当我尝试升级到最新版本时,出现无法解决依赖关系"问题.

I have a ASP.NET WebForms application that uses some Ninject packages, but I am stuck at a certain version. When I try to upgrade to the latest version, I get "Unable to resolve dependencies" issues.

有问题的包是:

Package                       InstalledVer   LatestVer
------------------------------------------------------
Ninject                       v3.2.2         v3.3.4
Ninject.Web                   v3.2.1 ✔      v3.2.1
Ninject.Web.Common            v3.2.3         v3.3.1
Ninject.Web.Common.WebHost    v3.2.3         v3.3.1

如果我尝试更新 Ninject,我会得到:

If I try updating Ninject, I get:

无法解决依赖关系.'Ninject 3.3.4' 不兼容'Ninject.Web 3.2.1 约束:Ninject (>= 3.2.0 && < 3.3.0)'

Unable to resolve dependencies. 'Ninject 3.3.4' is not compatible with 'Ninject.Web 3.2.1 constraint: Ninject (>= 3.2.0 && < 3.3.0)'

但是 Ninject.Web 已经是最新版本了!

but Ninject.Web is already at the latest version!

我应该更改 Ninject.Web 的依赖行为还是不安全?如果我这样做,我应该将依赖行为更改为什么?

Should I change the Dependency behaviour of Ninject.Web or would this be unsafe? If I do, what should I change the Dependency behavior to?

谢谢

推荐答案

好的,这就是解决方法:

Okay, so this is how to fix:

  1. 完全删除 Ninject.Web 包.不再需要此包,因为它现在已集成到 Ninject.Web.Common(好吧,无论如何,版本是 v3.3+)
  2. 更新包 NinjectNinject.Web.CommonNinject.Web.Common.WebHost.这些现在应该升级好了.对我来说,它们都是 v3.3.1.
  3. 作为软件包升级的一部分,将添加一个新文件 App_StartNinject.Web.Common.cs.这只是对现有 App_StartNinjectWeb.Common.cs 的重命名,因此 [a] 删除新文件或 [b] 迁移您的 Ninject 模块注册并删除旧文件.
  4. web.config 中,您现在应该删除 OnePerRequestModule 模块:

  1. Remove the Ninject.Web package completely. This package is no longer required as it is now integrated into Ninject.Web.Common (well, version v3.3+ anyway)
  2. Update the packages Ninject, Ninject.Web.Common and Ninject.Web.Common.WebHost. These should now upgrade okay. For me, they are both v3.3.1.
  3. As part of the package upgrade a new file App_StartNinject.Web.Common.cs will have been added. This is just a rename of the existing App_StartNinjectWeb.Common.cs so either [a] delete the new file or [b] migrate over your Ninject module registrations and remove the old file.
  4. In web.config, you should now remove the OnePerRequestModule module:

 <system.webServer>
     <modules runAllManagedModulesForAllRequests="true">
         <add name="OnePerRequestModule" type="Ninject.Web.Common.OnePerRequestHttpModule" />
     </modules>
 </system.webServer>

这是因为此模块在加载时动态注册在 App_StartNinject.Web.Common.cs 文件的 Start() 方法中:

This is because this module, is registered dynamically on loadup in the App_StartNinject.Web.Common.cs file's Start() method:

public static void Start()
{
    DynamicModuleUtility.RegisterModule(typeof(OnePerRequestHttpModule));
    DynamicModuleUtility.RegisterModule(typeof(NinjectHttpModule));
    bootstrapper.Initialize(CreateKernel);
}

如果您不从 web.config 中删除此条目,则在启动应用程序时可能会出现类型异常,尤其是因为作为版本更新的一部分,该类已从 Ninject.Web 中移出.Common 命名空间到 Ninject.Web.Common.WebHost.

If you don't remove this entry from web.config then you can expect a type exception when launching your application, not least because as part of the version update, the class has moved from the Ninject.Web.Common namespace to Ninject.Web.Common.WebHost.

你也可以出于同样的原因删除文件App_StartNinjectWeb.cs(注册NinjectHttpModule)

You can also remove the file App_StartNinjectWeb.cs for the same reason (registering NinjectHttpModule)

如果 OnePerRequestHttpModuleApp_StartNinject.Web.Common.cs 中无法解析,则将以下 using 语句添加到文件 using Ninject.Web.Common.WebHost;(我认为这是 v3.3.1 包中缺少的参考.

If OnePerRequestHttpModule doesn't resolve in App_StartNinject.Web.Common.cs then add the following using statement to the file using Ninject.Web.Common.WebHost; (I think this is a missing reference in v3.3.1 of the package.

希望这对其他人有所帮助.

Hope this helps others.

这篇关于无法在 Nuget 中将 Ninject 升级到最新版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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