Web API2 NinjectWebCommon.cs 不出现

Web API2 NinjectWebCommon.cs do not appear(Web API2 NinjectWebCommon.cs 不出现)
本文介绍了Web API2 NinjectWebCommon.cs 不出现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Visual Studio 2013 中做一个 Empty Web API Framework 4.5.显然 NinjectWebCommon.cs 没有出现.

I am doing an Empty Web API in Visual Studio 2013 Framework 4.5. Obviously NinjectWebCommon.cs do not appear.

我是通过 Nuget 安装的,

I installed via Nuget,

  • 忍者,

Ninject.Web.Common,

Ninject.Web.Common,

Ninject.MVC5,

Ninject.MVC5,

Ninject.Web.Common.WebHost,

Ninject.Web.Common.WebHost,

Ninject.Web.WebApi,

Ninject.Web.WebApi,

Ninject.web.WebApi.WebHost

Ninject.web.WebApi.WebHost

但是NinjectWebCommon.cs仍然没有出现.

我还需要安装什么?

我可以手动添加那个文件吗?

Can I add that file manually?

谢谢

推荐答案

看起来最新的 Ninject.Web.Common.WebHost 3.3.0 NuGet 包不再包含 NinjectWebCommon.cs.旧版本(例如 3.2.0)确实包含此文件.

It looks like the most recent Ninject.Web.Common.WebHost 3.3.0 NuGet package no longer includes the NinjectWebCommon.cs. Older versions, such as 3.2.0 do include this file.

Ninject.Web.Common.WebHost 3.3.0 提供了一个 NinjectHttpApplication 类,您可以从中派生和使用该类,而不是 NinjectWebCommon.cs.Ninject 的 wiki 文档 没有似乎已经更新,但看起来使用 NinjectHttpApplication 是一种记录方法,如下所示:

Ninject.Web.Common.WebHost 3.3.0 provides a NinjectHttpApplication class you can derive from and use instead of the NinjectWebCommon.cs. The wiki documentation for Ninject does not seem to have been updated but it looks like using the NinjectHttpApplication is one documented approach, as shown below:

public class MvcApplication : NinjectHttpApplication
{
   public static void RegisterGlobalFilters(GlobalFilterCollection filters)
   {
       filters.Add(new HandleErrorAttribute());
   }

   public static void RegisterRoutes(RouteCollection routes)
   {
       routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

       routes.MapRoute(
           "Default", // Route name
           "{controller}/{action}/{id}", // URL with parameters
           new
           {
               controller = "Home",
               action = "Index",
               id = UrlParameter.Optional
           });
   }

   protected override IKernel CreateKernel()
   {
       var kernel = new StandardKernel();
       RegisterServices(kernel);
       return kernel;
   }

   /// <summary>
   /// Load your modules or register your services here!
   /// </summary>
   /// <param name="kernel">The kernel.</param>
   private void RegisterServices(IKernel kernel)
   {
       // e.g. kernel.Load(Assembly.GetExecutingAssembly());
   }

   protected override void OnApplicationStarted()
   {
       base.OnApplicationStarted();

       AreaRegistration.RegisterAllAreas();
       RegisterGlobalFilters(GlobalFilters.Filters);
       RegisterRoutes(RouteTable.Routes);
   }
}

这篇关于Web API2 NinjectWebCommon.cs 不出现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)