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.
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)
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....
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.
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.
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.
I Have same problem. 1) I install latest (but unstable) Ninject for Web.Api from PM console using command
PM> Install-Package Ninject.Web.WebApi -Pre
2) Then i add this to "using" section of NinjectWebCommon.cs
using Ninject.Web.WebApi.FilterBindingSyntax;
After these steps my IKernel has method BindHttpFilter. And all works well
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With