如何使用Ninject用的ASP.NET Web API? [英] How to use Ninject with ASP.NET Web API?
问题描述
在MVC我只是使课堂 NinjectControllerFactory
实现 DefaultControllerFactory
接口,然后做一些绑定在里面。最后在全球
我运行它:
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?还有网络上的一些信息,但过时和pre-发布的版本。
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.
最好的两个走,几点思考是:
The best two walk-thoughs are:
- http://www.strathweb.com/2012/05/using-ninject-with-the-latest-asp-net-web-api-source/
- http://www.peterprovost.org/blog/2012/06/19/adding-ninject-to-web-api/
这篇关于如何使用Ninject用的ASP.NET Web API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!