Cannot upgrade Ninject to latest version in Nuget

ε祈祈猫儿з 提交于 2019-12-23 13:03:56

问题


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.

The packages in question are:

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

If I try updating Ninject, I get:

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)'

but Ninject.Web is already at the latest version!

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?

Thanks


回答1:


Okay, so this is how to fix:

  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_Start\Ninject.Web.Common.cs will have been added. This is just a rename of the existing App_Start\NinjectWeb.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>
    

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

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

    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.

  5. You can also remove the file App_Start\NinjectWeb.cs for the same reason (registering NinjectHttpModule)

  6. If OnePerRequestHttpModule doesn't resolve in App_Start\Ninject.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.



来源:https://stackoverflow.com/questions/52272485/cannot-upgrade-ninject-to-latest-version-in-nuget

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!