使用Ninject到绑定的WebAPI筛选属性 [英] Using Ninject to Bind WebApi Filter Attributes

查看:153
本文介绍了使用Ninject到绑定的WebAPI筛选属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前使用ninject.mvc3在我的asp.net的WebAPI项目,它工作正常。我现在想绑定过滤器属性,但 BindFilter BindHttpFilter 的iKernel <失踪/ code>使用 NinjectWebCommon 静态类方法时接口。如果我添加 Ninject.Web.WebApi 包,它的存在,但该项目将无法运行(问题<一href=\"http://stackoverflow.com/questions/11207766/issue-using-asp-net-mvc-4-web-api-with-ninject-web-webapi\">here,解决方案说, Ninject.Web.WebApi 是德precated),所以我删除了回去。

I'm currently using ninject.mvc3 in my asp.net webapi project, and it works fine. I am now trying to bind filter attributes, but BindFilter and BindHttpFilter are missing from IKernel interface when using the NinjectWebCommon static class method. If I add the Ninject.Web.WebApi package, its there but the project does not run (problem here, solution said that Ninject.Web.WebApi is deprecated) so I removed it back.

我也遵循了这一 github上维基准确,仍然 this.BindFilter 没有被发现。我有最新的NuGet包; Ninject(3.0.1.10),Ninject.Web.Common(3.0.0.7),Ninject.MVC3(3.0.0.6)

I also followed this github wiki exactly and still this.BindFilter was not found. I have the latest nuget packages; Ninject (3.0.1.10), Ninject.Web.Common (3.0.0.7), Ninject.MVC3 (3.0.0.6)

在哪里BindFilter或BindHttpFilter?做了什么改变?如何绑定在asp.net网页API过滤器的属性?有这么多的库和项目与文档不告诉你什么是当前的工作之一,是什么pcated德$ P $ ....

Where Is BindFilter or BindHttpFilter? Did something change? How do I bind filter attributes in asp.net web api? There are so many libraries and projects and the docs don't tell you what is the current working one and what is deprecated....

推荐答案

您所使用的包装用它们不包括尚未BindHttpFilter是正确的。 BindHttpFilter扩展方法是 https://github.com/remogloor/Ninject.Web.WebApi这是目前不适合的WebAPI的发行版的工作,因为它是写对测试的WebAPI版本。为了注入到你需要BindHttpFilter一个的WebAPI过滤器,你可以不通过的WebAPI滤入BindFilter方法​​。

The packages you are using are correct by they don't include BindHttpFilter yet. BindHttpFilter extension method is from https://github.com/remogloor/Ninject.Web.WebApi which is currently not working for the release version of WebApi as it was written against the beta WebApi version. In order to inject into a WebApi filter you need BindHttpFilter, you can't pass a WebApi filter into the BindFilter method.

这是 https://github.com/ninject/Ninject.Web。的WebAPI /拉/ 1 似乎是我能找到在一个更新的状态的最新信息。

This is https://github.com/ninject/Ninject.Web.WebApi/pull/1 seems to be the latest info I could find on the status of an update.

您也可以尝试其他的NuGet包 http://nuget.org/packages/Ninject .Web.WebApi-RC 但是我已经和它的一些错误,现在不记得到底是什么错误。阅读上述拉入请求的讨论后,无论如何,我放弃了这个包。

You could also try another NuGet package http://nuget.org/packages/Ninject.Web.WebApi-rc but I had some errors with it, don't remember now exactly what errors. Anyway after reading the discussion on the above mentioned pull request I gave up on this package.

在我来说,我想实现一个日志过滤器,所以我只是要创造,我可以从过滤器注入到支持电话将提供一个静态方法。

In my case I am trying to implement a logging filter so I am just going to create a static method that I can call from the filter till injection support will be available.

这篇关于使用Ninject到绑定的WebAPI筛选属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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