如何使用ASP.NET Web API的Ninject? [英] How to use Ninject with ASP.NET Web API?

查看:153
本文介绍了如何使用ASP.NET Web API的Ninject?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在MVC中,我只需要实现 DefaultControllerFactory 接口的类 NinjectControllerFactory ,然后在其中执行一些绑定。最后在全球我运行它:

In MVC I simply make the class NinjectControllerFactory that implements DefaultControllerFactory interface then do some bindings in it. at last in Global I run it:

ControllerBuilder.Current.SetControllerFactory(new NinjectControllerFactory());

但是如何在ASP.NET Web API中使用Ninject?有一些网络上的信息,但是已经过期,并且预发布的版本。

But what about using Ninject in ASP.NET Web API? there are some information on the web but are out dated and for pre-released versions.

这个问题有直接的方法吗?

推荐答案

很多文章很旧的原因是因为2012年6月以来的方法没有改变(RC发布5月31日)。您需要添加Ninject MVC3 Nuget软件包,然后实现IDepenencyResolver,然后注册您的实现。

The reason a lot of the articles are old is because the approach hasn't changed since June 2012 (RC released May 31st). You need to add the Ninject MVC3 Nuget package, then implement 'IDepenencyResolver' and then register your implementation.

最好的两个步骤是:


  1. http://www.strathweb.com/2012/05/using-ninject-with-the-latest-asp-net-web-api-source/

  2. http://www.peterprovost.org/blog/2012/06/19/adding-ninject-to-web-api/

  1. http://www.strathweb.com/2012/05/using-ninject-with-the-latest-asp-net-web-api-source/
  2. http://www.peterprovost.org/blog/2012/06/19/adding-ninject-to-web-api/

这篇关于如何使用ASP.NET Web API的Ninject?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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