3

I'm trying to use Dependency injection with an Action Filter Attribute for a normal MVC Controller (not WebAPI) according to this answer https://stackoverflow.com/a/6194159/894792

The articles that I've seen say that you have to use kernel.BindFilter<>(), but that doesn't appear for my Kernel.

using Ninject;
using Ninject.Web.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http.Dependencies;
using uQuiz.Domain;
using uQuiz.Domain.Abstract;
using uQuiz.Domain.Concrete;
using uQuiz.Domain.Models;

namespace uQuiz.WebUI.Infrastructure
{
    /// <summary>
    /// Dependency Resolver for Ninject, called within NinjectWebCommon.cs in App_start folder
    /// </summary>
    public class NinjectDependencyResolver : NinjectScope, IDependencyResolver
    {
        private IKernel kernel;

        public NinjectDependencyResolver(IKernel kernelParam)
            : base (kernelParam)
        {
            this.kernel = kernelParam;
            this.AddBindings();
        }

        public IDependencyScope BeginScope()
        {
            return new NinjectScope(kernel.BeginBlock());
        }

        private void AddBindings()
        {
            this.kernel.Bind(typeof(IQuizEntities)).To(typeof(QuizEntities)).InRequestScope();

            // No BindFilter method
            // this.kernel.BindFilter()
        }
    }
}

I am using Ninject.MVC3.

Where is the BindFilter method? It's here in the Ninject Docs

Community
  • 1
  • 1
Luke
  • 22,826
  • 31
  • 110
  • 193

1 Answers1

13

I required the following using statement in my Ninject Dependency Resolver:

using Ninject.Web.Mvc.FilterBindingSyntax;
Luke
  • 22,826
  • 31
  • 110
  • 193