控制器和操作上的Ninject和MVC3依赖注入操作过滤器出现问题 [英] Problem with Ninject and MVC3 Dependency injection action filter on Controller and Action

查看:110
本文介绍了控制器和操作上的Ninject和MVC3依赖注入操作过滤器出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,我决定删除控制器中的一堆动作级别过滤器,并用单个控制器级别过滤器替换它们.

Recently I decided to remove a heap of action level filters in a controller and replace them with a single controller level filter.

现在我收到此错误消息.

Now I'm getting this error message.


Error activating LogActionFilter
More than one matching bindings are available.
Activation path:
 1) Request for LogActionFilter

Suggestions:
 1) Ensure that you have defined a binding for LogActionFilter only once.

我确定该错误与动作过滤器绑定两次有关,因为这就是我所做的更改.但是,当我在此处查看文档时,我可以看到它指定/执行相同的操作.所以我真的不确定我在做什么错.

I'm sure the error is related to action filter being bound twice, as that's what I've changed. However, when I view the documentation here I can see it specifies/does the same. So I'm really not sure what I'm doing wrong.

我的样品控制器

[LogAction]
public class SomeController : Controller
{
    public ActionResult SomeAction()
    { 

    }
}

我的注册码

public static void RegisterFilters()
{
    Kernel.BindFilter<LogActionFilter>(FilterScope.Controller, 0)
    .WhenControllerHas<LogActionAttribute>();

    Kernel.BindFilter<LogActionFilter>(FilterScope.Action, 0)
        .WhenActionMethodHas<LogActionAttribute>();
}

推荐答案

如果您的控制器及其操作之一同时具有LogActionAttribute,则会发生这种情况.

This happens if your controller and one of its actions have the LogActionAttribute at the same time.

这篇关于控制器和操作上的Ninject和MVC3依赖注入操作过滤器出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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