gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 09:08:42 25 4
gpt4 key购买 nike

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

Error occured: Error activating SomeControllerMore than one matching bindings are available.Activation path:  1) Request for SomeControllerSuggestions:  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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com