在Dependency Resolver Kernel中找不到BindFilter方法

时间:2014-11-06 12:37:53

标签: asp.net-mvc ninject action-filter actionfilterattribute

我正在尝试根据这个答案https://stackoverflow.com/a/6194159/894792

将依赖注入与正常MVC控制器(而不是WebAPI)的动作过滤器属性一起使用

我见过的文章说你必须使用kernel.BindFilter<>(),但这不会出现在我的内核中。

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()
        }
    }
}

我正在使用Ninject.MVC3

BindFilter方法在哪里?它在Ninject Docs

1 个答案:

答案 0 :(得分:11)

我在Ninject Dependency Resolver中需要以下using语句:

using Ninject.Web.Mvc.FilterBindingSyntax;