asp.net-mvc - 使用 Ninject.Web.Mvc 2.0 和 ASP.NET MVC 1.0 时出现错误 "More than one matching bindings are available"

标签 asp.net-mvc ninject

最近我切换到 Ninject 2.0 版本并开始收到以下错误:

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

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

However, I'm unable to find certain reproduction path. Sometimes it occurs, sometimes it does not. I'm using NinjectHttpApplication for automatic controllers injection. Controllers are defined in separate assembly:

public class App : NinjectHttpApplication
{
    protected override IKernel CreateKernel()
    {
        INinjectModule[] modules = new INinjectModule[] {
            new MiscModule(),
            new ProvidersModule(),
            new RepositoryModule(),
            new ServiceModule()
        };

        return new StandardKernel(modules);
    }

    protected override void OnApplicationStarted()
    {
        RegisterRoutes(RouteTable.Routes);
        RegisterAllControllersIn("Sample.Mvc");
        base.OnApplicationStarted();
    }

    /* ............. */

}

也许有人熟悉这个错误。

有什么建议吗?

最佳答案

你确定你真的在创建一个全新的Kernel在您的 OnApplicationStarted 中从头开始每次调用它?如果您不是,并且您实际上创建了一次,但可能会运行两次注册位。请记住,您不能保证只有一个 App在给定的 AppDomain 中实例化的类。

关于asp.net-mvc - 使用 Ninject.Web.Mvc 2.0 和 ASP.NET MVC 1.0 时出现错误 "More than one matching bindings are available",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2423862/

相关文章:

dependency-injection - 使用上下文信息记录日志

c# - 关于使用 Ninject 的问题

asp.net-mvc - 我应该如何在多项目 mvc 应用程序中使用 ninject?

c# - 对已定义命名空间中的所有类使用 Ninject.InSingletonScope()

javascript - ASP.NET MVC Web API 使用 jQuery Ajax 删除调用,数据参数不起作用

ModelState为Invalid时提交数据后的Ajax表单和UpdateTargetId

c# - 使用选择更改淡出或淡入另一个字段

c# - 有效的 RegEx 不适用于 ASP.Net MVC RegularExpression 属性

asp.net-mvc-3 - ninject 依赖解析器和服务定位器实现

asp.net-mvc - 从 Web 应用程序中删除已保存的浏览器用户名和密码